Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Ask SQLTeam Question

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.


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?


Most Valuable Yak

15732 Posts

Posted - 09/14/2004 :  08:20:53  Show Profile  Visit robvolk's Homepage  Reply with Quote
Don't use loops. Try this:

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


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
It returns a table from a csv string.

This one
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  
 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.02 seconds. Powered By: Snitz Forums 2000