Home Forums SQL Server 7,2000 T-SQL Case Statement to return multiple columns RE: Case Statement to return multiple columns

  • vani_r14 (9/23/2013)


    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

    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/