| 
                
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 |  
                                    | AskSQLTeamAsk SQLTeam Question
 
 
                                        0 Posts | 
                                            
                                            |  Posted - 2004-09-14 : 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" |  |  
                                    | robvolkMost Valuable Yak
 
 
                                    15732 Posts | 
                                        
                                          |  Posted - 2004-09-14 : 08:20:53 
 |  
                                          | Don't use loops.  Try this:http://www.sqlteam.com/item.asp?ItemID=2652Once 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. |  
                                          |  |  |  
                                    | nrSQLTeam MVY
 
 
                                    12543 Posts | 
                                        
                                          |  Posted - 2004-09-14 : 22:17:42 
 |  
                                          | Have a look at thishttp://www.nigelrivett.net/ParseCSVString.htmlIt returns a table from a csv string.This onehttp://www.nigelrivett.net/f_GetEntryDelimiitted.htmlyou pass the string and field number you want and it returns itas inselect 	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. |  
                                          |  |  |  
                                |  |  |  |  |  |