I need to split a pipe-delimited field (‘Y|N|Y|Y’).
I found the recursive function listed here
T-SQL: Opposite to string concatenation – how to split string into multiple records
but it creates the values into new records.
row field
1 Y
2 N
3 Y
4 N
I need to transform ‘Y|N|Y|Y’
field
'Y|N|Y|Y'
into
field1 | field2 | field3 | field4
y N Y N
Can someone point me in the right direction? Would it make it easier if I said the number of values is fixed (it will probably be 8 values delimited in one field).
Update: A possible field value could be this (note the blank value):
‘Y|10|N|1||Y’
**EDIT: **Mine still works for the sample string
Here’s an alternative answer, since you know the widths are a fixed length:
EDIT: I knew I saw this somewhere before when I came across a similar problem:
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/381e4164-f1e0-4b54-828f-2795d2cdcb3e/