| Author |
Topic  |
|
|
AskSQLTeam
Ask SQLTeam Question
USA
0 Posts |
Posted - 09/14/2004 : 08:17:43
|
Phil writes "How do I get the first key, then the second, then the third etc. in a string of characters seperated by a comma? I want to loop through each key in the string and do some SQL statement's each time.
key1,key2,key3,key(whatever)
first time through the loop I want key1, then I want key2, etc.
I know how to get the first key, but how do I keep track of where I'm at in the loop?
Thanks, Phil" |
|
|
robvolk
Most Valuable Yak
USA
15557 Posts |
Posted - 09/14/2004 : 08:20:53
|
Don't use loops. Try this:
http://www.sqlteam.com/item.asp?ItemID=2652
Once you have the results in a table, you can process the entire set in one operation, instead of working one-by-one in a loop. |
 |
|
|
nr
SQLTeam MVY
United Kingdom
12543 Posts |
Posted - 09/14/2004 : 22:17:42
|
Have a look at this http://www.nigelrivett.net/ParseCSVString.html It returns a table from a csv string.
This one http://www.nigelrivett.net/f_GetEntryDelimiitted.html you pass the string and field number you want and it returns it as in select Forname = dbo.f_GetEntryDelimiitted (@s, 1, ',', 'Y') , Surname = dbo.f_GetEntryDelimiitted (@s, 2, ',', 'Y')
========================================== 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. |
 |
|
| |
Topic  |
|
|
|