Dynamic SQl and output

  • I want to exec(@sql)

    but i am strruggling when the SP has outputs. How do I do this?

    Many thanks

  • Hi, you should look into sp_executesql instead of EXECUTE. For Details please see BooksOnLine (BOL).

    You also might have a look at http://www.sommarskog.se/dynamic_sql.html

    If you need more information please tell us a little more what you're looking for.

    For details on how to post sample data please see http://www.sqlservercentral.com/articles/Best+Practices/61537/



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Edward (6/9/2009)


    I want to exec(@sql)

    but i am strruggling when the SP has outputs. How do I do this?

    Many thanks

    It depends on what kind of outputs you mean (IIRC, there are three kinds). Parameter outputs require the use of sp_executesql. The other two (RETURN value and result set) can be handled almost identically to how they are handled with a stored procedure call.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 3 posts - 1 through 2 (of 2 total)

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