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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Parsing Strings

Author  Topic 

ramdas
Posting Yak Master

181 Posts

Posted - 2003-08-05 : 15:25:35
Hi folks,
I have a string which is passed to the stored procedure like
A|B|C|D, how do I parse it to get values like
A
B
C
D

Thank you
Ramdas

Ramdas Narayanan
SQL Server DBA

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-05 : 15:37:01
This artcile should help you:

[url]http://www.sqlteam.com/item.asp?ItemID=2652[/url]

It shows how to parse CSV values into multiple rows, but just change the comma to a pipe in the code.

Tara
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-08-05 : 16:25:40
Note that if it is truly only letters and the string is guaranteed to be well-formed, you can do something like this:

(assuming you have a table called Numbers with an int called "Number" from 1 - 1000 or so)

select substring(@String, (Number-1)*2 +1,1) as Letter
from
Numbers
where Number < len(@string) / 2

same basics as the article, but much simplier since you are dealing with fixed-length items in the string.


- Jeff
Go to Top of Page
   

- Advertisement -