Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
slim
Starting Member
3 Posts |
Posted - 2005-01-18 : 04:54:29
|
| Hi,I am trying to load an array from a column in 1 table to another tablewhere each element of the array will have it's own column ie:Table ACol11 0 0 33 0 0 I need the data to be split into seperate cols :Table BCol1 Col2 Col3 Col4 Col5 Col61 0 0 33 0 0Now I can do this using dynamic SQL and a cursor but the problem is that I have several million rows, so ideally I would like to use a set-based operation. I have looked at table functions but the problem there is using a table as a parameter doesn't seem to work. Anyone got any ideas? Thanks |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-01-18 : 05:07:13
|
| seehttp://www.mindsdoor.net/SQLTsql/f_GetEntryDelimiitted.htmlandinsert tblbselect dbo.f_GetEntryDelimiitted(col1, 1, ' ', 'N') ,dbo.f_GetEntryDelimiitted(col1, 2, ' ', 'N') ,dbo.f_GetEntryDelimiitted(col1, 3, ' ', 'N') ,dbo.f_GetEntryDelimiitted(col1, 4, ' ', 'N') ,dbo.f_GetEntryDelimiitted(col1, 5, ' ', 'N') ,dbo.f_GetEntryDelimiitted(col1, 6, ' ', 'N')from tblaThis will be quite slow for that number of recs. Try it and see.You can make it more efficient by using a temp table to hold the position so you don't start from the first entry in the row each time.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
hgorijal
Constraint Violating Yak Guru
277 Posts |
Posted - 2005-01-18 : 06:23:52
|
| BCP OUT the column into a file and then BCP IN the file into the second table with the column delimiter as ' '. This could be much faster for your several million rows.hth.Hemanth GorijalaExchange a Dollar, we still have ONE each._______Exchange an Idea, we both have TWO each. |
 |
|
|
slim
Starting Member
3 Posts |
Posted - 2005-01-18 : 06:30:38
|
| Thanks for the replies lads,NR - looks interesting I will take a closer look. Hgorijal, I know that works, the problem is tight security in my current environment. However if all else fails, then I'll have to push that solution.Cheers |
 |
|
|
|
|
|
|
|