| Author |
Topic |
|
tarz
Starting Member
31 Posts |
Posted - 2008-03-04 : 10:45:29
|
| Hi I am trying to split a string and display its values.ie.I have SET @c='7890A098908A90809A22'output should look like:VALUE1 VALUE2 VALUE3 VALUE47890 098908 90809 22Please advice, Thank you |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-03-04 : 10:49:13
|
| look up substring and charindex. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-03-04 : 10:49:54
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-04 : 11:09:22
|
| declare @c varchar(100)SET @c='7890A098908A90809A22'select parsename(replace(@c,'A','.'),4),parsename(replace(@c,'A','.'),3),parsename(replace(@c,'A','.'),2),parsename(replace(@c,'A','.'),1)MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-04 : 11:16:57
|
| Keep in mind that you can apply PARSENAME only if you're sure you have a maximum of 4 values to be extracted to four different fields. If your string contains more than 4 values seperated by A then parsename wont work. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-04 : 11:33:40
|
quote: Originally posted by visakh16 Keep in mind that you can apply PARSENAME only if you're sure you have a maximum of 4 values to be extracted to four different fields. If your string contains more than 4 values seperated by A then parsename wont work.
Yes it is.For any number of columnsdeclare @s varchar(8000)select @s='7890A098908A90809A22'select @s=''''+replace(@s,'A',''',''')+''''exec('select '+@s)MadhivananFailing to plan is Planning to fail |
 |
|
|
tarz
Starting Member
31 Posts |
Posted - 2008-03-04 : 11:57:44
|
| Thank you all for your help, Is there away to add column-names as well to the output? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-05 : 03:18:20
|
quote: Originally posted by tarz Thank you all for your help, Is there away to add column-names as well to the output?
Where do you want to show data?MadhivananFailing to plan is Planning to fail |
 |
|
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2008-03-05 : 22:27:50
|
quote: Originally posted by khtan http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033 KH[spoiler]Time is always against us[/spoiler]
What does a split on delimiters have to do with this?--Jeff Moden |
 |
|
|
|