LearnItFirst User Forum

SQL Server 2008 SSAS Training Videos
Welcome Guest Search | New Posts | Members | Log In | Register

Cursor help Options
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

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.
Users browsing this topic
Guest


Forum Jump
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.