Home Forums SQL Server 2008 T-SQL (SS2K8) Passing Multiple Values As Parameters to get Multiple Columns with Comma Seperation(MSSQL) RE: Passing Multiple Values As Parameters to get Multiple Columns with Comma Seperation(MSSQL)

  • j.miner (4/8/2013)


    select @var_months3 =

    (

    case

    when @var_cnt = 1 then 'jan'

    when @var_cnt = 2 then 'feb'

    when @var_cnt = 3 then 'mar'

    when @var_cnt = 4 then 'apr'

    when @var_cnt = 5 then 'may'

    when @var_cnt = 6 then 'jun'

    when @var_cnt = 7 then 'jul'

    when @var_cnt = 8 then 'aug'

    when @var_cnt = 9 then 'sep'

    when @var_cnt = 10 then 'oct'

    when @var_cnt = 11 then 'nov'

    when @var_cnt = 12 then 'dec'

    else 'unk'

    end

    )

    Just as a suggestion... please consider the following which takes a whole lot less typing and is twice as fast when running.

    SELECT @var_months3 = CONVERT(CHAR(3),DATEADD(mm,@var_cnt-1,0),100);

    For proof of the performance pudding, please see the following article.

    http://www.sqlservercentral.com/articles/formatting/72066/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)