home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
Transact-SQL Programming
»
Stored Procedures, Triggers, & Functions
»
Cursor help
Cursor help
Options
Previous Topic
·
Next Topic
anaylor01
Posted:
Wednesday, December 03, 2008 8:40:59 AM
Rank: Newbie
Joined: 12/24/2007
Posts: 3
Points: 9
Where do you live?: NYC
I have a one column table. The data in that column has 1142 characters. It is fixed delimited data. To make it more dynamic for parsing the data I have created a table that has the fieldname, fieldlength and field size. I want to create a cursor that will parse this data into the correct fields into a table. When I run this it puts the data into the first field. Lets say there are 50 records in the One column table. Well it puts the first 50 rows into the new table but it starts the second field at 51 and so on and so forth.
Declare DDOKRaw cursor for
Select [field name],startingposition, fieldlength from dbo.TablefieldPositionLength
Declare @fn varchar(128)
Declare @sp varchar(128)
Declare @fl varchar(128)
Open DDOKRAW
Fetch Next From DDOKRaw into @fn, @sp, @fl
set @rownum = 1
While @@Fetch_Status = 0
Begin
EXEC('insert into migr0173 (' + @fn + ') select top 1 substring(data,' + @sp + ', ' + @fl + ') as ' + @fn + ' from dbo.MIGR0173_20080917061003')
Fetch Next From DDOKRaw into @fn, @sp, @fl
end
Close DDOKRaw
Deallocate DDOKRaw
Back to top
Scott Whigham
Posted:
Thursday, December 04, 2008 10:48:16 AM
Rank: Super Mod
Joined: 3/20/2006
Posts: 476
Points: 1,053
Where do you live?: Dallas, TX
Can you give us some example data? I'm 99.9999% positive that a cursor is not the preferred/best way but I need some sample data to work from.
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
You
cannot
post new topics in this forum.
You
cannot
reply to topics in this forum.
You
cannot
delete your posts in this forum.
You
cannot
edit your posts in this forum.
You
cannot
create polls in this forum.
You
cannot
vote in polls in this forum.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded