Concatenating Dynamic SQL

  • Comments posted to this topic are about the item Concatenating Dynamic SQL

  • The answer should be: I get the two statements concatenated together, not the strings are concatenated, because there is no execution!

    Have a nice day,Christoph

  • What Christoph said ^^

    None of the answers provided apply... has anyone even proof-read them??

  • Yeah, I think I'll sit this one out for a bit...

    Just because you're right doesn't mean everybody else is wrong.

  • Yes,  I had to try it out to prove to myself that "SELECT @sql" wasn't some underhand feature I didn't know about but of course I got the 2 query strings concatenated. ..


    ALSO bugged no-one checked this before posting

    At the end of most articles is a small blurb called a person's signature which exists to provide information about how to get in touch with the person posting, including their email address, phone number, address, or where they're located. Signatures have become the graffiti of computers. People put song lyrics, pictures, philosophical quotes, even advertisements in them. (Note, however, that advertising in your signature will more often than provoke negative responses until you take it out.)

  • NOTA.  None of the above

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:

  • Email had "Select @SQL" on the site it said "EXEC (@SQL). In first case you get 2 statements concatenated into one, in second case you get 2 separate recordsets. None of the options is a good answer.

  • None of the answers are correct.

  • Spoiler:

    Question as is: I execute this code on SQL Server 2019. Each of the tables has one row in it. What happens?


    SET @SQL = 'SELECT mystring FROM TableA;';
    SET @SQL += 'SELECT mystring FROM TableB;';


    Based on the current text of the question above there should be an answer available that says something like, "Two results sets are returned, one with the mystring value(s) from TableA and another with the mystring value(s) from TableB." The only answer close is "I get the strings from TableA and TableB concatenated together" but while this is close it's still incorrect since the result sets aren't concatenated; they'd be returned as two separate result sets not one concatenated together.


  • Glad to see that I'm not alone in my confusion here! None of the answers fit the actual situation. As I expected, I got a result set from each table.

  • It is unfortunate that the problem text in the email for which the final answer is correct and the text of the problem on the answer page, and for which no answer is correct, do not match.  Poor editing as mentioned.  Maybe someone will correct the answer page.

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

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