September 23, 2013 at 11:33 pm
Hi all
am trying to write a case statement an that currently returns one column. Is there any way that it could return multiple columns.
for e.g.
case when <condition> then (Select substring(column, 1, 3)) as Col1, (Select substring(column, 4, 2)) as Col2
else '' end
Can some one please help. It feels like it's not possible unless I write multiple case statements, but just wanted to check.
Thanks
vani
September 24, 2013 at 8:08 am
vani_r14 (9/23/2013)
Hi allam trying to write a case statement an that currently returns one column. Is there any way that it could return multiple columns.
for e.g.
case when <condition> then (Select substring(column, 1, 3)) as Col1, (Select substring(column, 4, 2)) as Col2
else '' end
Can some one please help. It feels like it's not possible unless I write multiple case statements, but just wanted to check.
Thanks
vani
No you can't do that. A case expression is used to help decide the value for a column. Also you don't need subselects inside like that.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 25, 2013 at 12:23 am
Thank you Sean. I thought so. 🙂
Cheers
Vani
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply