Dynamic SQL calls

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715053

    Comments posted to this topic are about the item Dynamic SQL calls

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71310

    Nice, easy question to end the week on, thanks, Steve

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • HappyGeek

    SSCoach

    Points: 18661

    Good question, thanks Steve.

    ...

  • Lynn Pettis

    SSC Guru

    Points: 442118

    Considering how much dynamic SQL I write where I work, this was a very easy question.  I use sp_executesql extensively in my code where I need to run dynamic SQL.

  • johnfowler

    Ten Centuries

    Points: 1126

    It seems to me the second answer could be correct as well.  If the DECLARE statement included a value for @CustomerKey then the query won't error.  So, if the second DECLARE statement was changed to:
    DECLARE @params NVARCHAR(1000) = '@CustomerKey int = 101';
    Then the query wouldn't error out and would return rows if there were rows containing a customer key of 101.

  • RLilj33

    SSCrazy

    Points: 2146

    +1 to johnfowler. While adjusting the @params statement to include a fixed value may not be very useful, it still works.

    • This reply was modified 4 months, 2 weeks ago by  RLilj33.

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

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