DECLARE multiple vars with default value

  • Comments posted to this topic are about the item DECLARE multiple vars with default value

    God is real, unless declared integer.

  • Just so people don't get confused, the question was about what happens when you try to make a cascading assignment using DECLARE.  The same does NOT hold true for making cascading assignments with SELECT.  For example, the following does work...

    DECLARE @s VARCHAR(5),
            @t VARCHAR(5)
    ;
     SELECT @s = 'test',
            @t = @s
    ;
    PRINT
     @t
    ;

    --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)

  • This was removed by the editor as SPAM

  • t.franz - Sunday, January 15, 2017 8:06 AM

    Comments posted to this topic are about the item DECLARE multiple vars with default value

    For the sake of completeness: In Jeff Modens example (first declare the variables and then SELECT @s-2='test', @t=@s) @t would contain the value 'test' (the variables will be set in the same order as they occur in the SELECT statement).

    God is real, unless declared integer.

  • Back to basics, thanks for the question.

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • t.franz - Monday, January 16, 2017 1:12 AM

    t.franz - Sunday, January 15, 2017 8:06 AM

    Comments posted to this topic are about the item DECLARE multiple vars with default value

    For the sake of completeness: In Jeff Modens example (first declare the variables and then SELECT @s-2='test', @t=@s) @t would contain the value 'test' (the variables will be set in the same order as they occur in the SELECT statement).

    For the sake of completeness, I was hoping that people would actually run the code. 😉

    --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)

  • Nice basics question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply