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
 Transact-SQL (2000)
 Manipulating a String (Pipe Delimited)

Author  Topic 

GoodFella3993
Starting Member

8 Posts

Posted - 2009-06-05 : 12:00:43
I have a string with multiple values separated by a pipe.
'ONE|TWO|THREE'

I have parsed it out into a table.

ONE
TWO
THREE

I now need to INSERT these records into one row in separate fields.

F1 F2 F3
ONE TWO THREE

Can I assign these values to a variable? I am doing this all through a cursor, so the original input is a variable.

Thanks,
Marc

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-06-05 : 13:21:59
assuming you have no more than 4 delimited values you could use PARSENAME to split them:

insert <yourTable>
select parsename(replace('ONE|TWO|THREE','|','.'), 3)
,parsename(replace('ONE|TWO|THREE','|','.'), 2)
,parsename(replace('ONE|TWO|THREE','|','.'), 1)


EDIT:
you should also search here for "split functions". They are handy for this sort of thing you can work on your entire table at once. No need for a cursor.

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-05 : 14:01:56
see one below

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113563
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-05 : 20:49:45
you don't have to parse into a table. Just use fnParseString to extract individual value


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -