SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 getting key in a comma delimited string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 09/14/2004 :  08:17:43  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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
15678 Posts

Posted - 09/14/2004 :  08:20:53  Show Profile  Visit robvolk's Homepage  Reply with Quote
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.
Go to Top of Page

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 09/14/2004 :  22:17:42  Show Profile  Visit nr's Homepage  Reply with Quote
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000