| Author |
Topic |
|
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2008-03-07 : 06:59:56
|
| HiI have a field that has the following value 001, 002, 003, 004I want to select the different value ascol col2 col3 col4001 002 003 004Sometimes there might only be one value, sometimes none sometimes two, three or fourThanks |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2008-03-07 : 07:12:31
|
| Declare @str varchar(50)set @str='001, 002, 003, 004'select parsename(replace(@str,',','.'),4)as col1,parsename(replace(@str,',','.'),3)as col2,parsename(replace(@str,',','.'),2)as col3,parsename(replace(@str,',','.'),1)as col4Note if the number of values if more than 4 then parsename wont work. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-07 : 08:04:31
|
| For any number of columnsDeclare @str varchar(50),@sql varchar(8000)set @str='001, 002, 003, 004, 005, 006'set @sql='select '''+replace(@str,',',''',''')+''''exec(@sql)MadhivananFailing to plan is Planning to fail |
 |
|
|
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2008-03-07 : 11:02:34
|
| thanks |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2008-03-07 : 13:44:48
|
| The better answer is "Please refer to Rule 1 of 12" ...Jayto here knows when |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-03-07 : 23:10:02
|
quote: Originally posted by Page47 The better answer is "Please refer to Rule 1 of 12" ...Jayto here knows when
What rules ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2008-03-09 : 20:21:09
|
| Uh oh ... don't end up in the "THE VOCIFEROUS IGNORANCE HALL OF SHAME" ... google relational database 12 rules quick ...Jayto here knows when |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-03-09 : 21:23:41
|
Pardon my ignorance. Never knew there are such rules.I guess, i make it to the hall of shame  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2008-03-11 : 16:06:13
|
| http://en.wikipedia.org/wiki/Codd%27s_12_rulesJayto here knows when |
 |
|
|
|