August 7, 2012 at 6:58 am
This is a tricky question and even though I knew the answer I got it wrong, but I blame myself for not putting enough attention.
However, the explanation is wrong and misleading. The query is not using a temporary table, is using a table variable. And the reference is to a microsoft forum where table variables are not mentioned.
The previous question was a fine exercise, but today's question seems just pointless.
August 7, 2012 at 7:04 am
Got Me, good question.
August 7, 2012 at 7:07 am
When my wife asks my a question that she already asked me a few days ago, I stop and think OH NO I BETTER REALLY PAY ATTENTION AND GIVE THIS SOME THOUGHT AND NOT JUST THE USUAL "sure honey whatever you want" ... just saying
August 7, 2012 at 7:21 am
tommyh (8/6/2012)
So here i was thinking this was a rewrite of the question we had 2 questions ago, since this question had the varchar(50) on str4 which would have fixed a lot of the issues with the that question. But unfortunatly it wasnt. Instead # had been changed for @.Besides what does this actually have to do with "Commenting in Dynamic query"?... nothing i tell you. The comments dont matter. This has more to do with "Scope".
First question was "interesting" if nothing else. This just bores me. Ah well... keep trying.
/T
Ugh, got me too! :-/
August 7, 2012 at 7:23 am
This is indeed the second question on this topic in a few days that is quite ridiculous. Why would I care how comments are handled inside dynamic sql? Has anybody ever actually written comments in their dynamic sql? If this were handed to me in a code review it would be rejected instantly. If this was something I needed to debug I would print the dynamic string so I could see what it actually contained.
I appreciate the effort of the poster but I am still not quite sure what we are trying to test. Commenting in dynamic sql or the scope of table variables?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 7, 2012 at 7:28 am
tommyh (8/6/2012)
So here i was thinking this was a rewrite of the question we had 2 questions ago, since this question had the varchar(50) on str4 which would have fixed a lot of the issues with the that question. But unfortunatly it wasnt. Instead # had been changed for @.Besides what does this actually have to do with "Commenting in Dynamic query"?... nothing i tell you. The comments dont matter. This has more to do with "Scope".
First question was "interesting" if nothing else. This just bores me. Ah well... keep trying.
/T
I have to agree... And what happened to Steve's statement of NO MORE IMAGES for queries?
Steve? Come on...
Not that it matters for this one... but it did look like a rewrite and fix of the original... I didn't even look closely at it.
Shame on me, shame on the author if this was actually intentional though.
August 7, 2012 at 7:29 am
Thomas Abraham (8/7/2012)
+2 - This question has GOTCHA written all over it. While I admit I should have been more careful in reading the question, the question title and the way it changed the 45 to 50 seems purposefully designed to lead people to the conclusion that it's a rewritten/corrected reversion of last week's question. If your intent was to catch people not finely parsing the question, then you succeeded. (I can see the smirk on the OPs face when submitting the question.) At any rate, I do not like the spirit of the question.
/Agreed whole heartedly.
August 7, 2012 at 7:31 am
Sean Lange (8/7/2012)
I appreciate the effort of the poster but I am still not quite sure what we are trying to test. Commenting in dynamic sql or the scope of table variables?
We're trying to test how far the OP can stick a finger in our eyes of course 🙂
August 7, 2012 at 7:32 am
Sean Lange (8/7/2012)
This is indeed the second question on this topic in a few days that is quite ridiculous. Why would I care how comments are handled inside dynamic sql? Has anybody ever actually written comments in their dynamic sql? If this were handed to me in a code review it would be rejected instantly. If this was something I needed to debug I would print the dynamic string so I could see what it actually contained.I appreciate the effort of the poster but I am still not quite sure what we are trying to test. Commenting in dynamic sql or the scope of table variables?
It's probably not something you'd want to do in production without a good reason, but it does come in handy when developing your dynamic SQL if you understand how it will be parsed... although often it's easier to debug the resulting query and back-port the changes into the dynamic SQL code.
It's also a good practical example of why you would want to avoid comments in dynamic SQL, and something to consider when reviewing your dynamic SQL for potential SQL injection issues.
August 7, 2012 at 8:54 am
thadeushuck (8/7/2012)
When my wife asks my a question that she already asked me a few days ago, I stop and think OH NO I BETTER REALLY PAY ATTENTION AND GIVE THIS SOME THOUGHT AND NOT JUST THE USUAL "sure honey whatever you want" ... just saying
Haha, this is good advice. :laugh:
August 7, 2012 at 9:09 am
A couple months ago, I learn by the hard way that you can't use table variables in dynamic SQL, when I had to optimize a sp based on dynamic SQL and I tried to include a table variable, and of course it fails.
At the end I replaced all the dynamic SQL with standard T-SQL, but the knowledge acquired was very useful for me today 😀
August 7, 2012 at 9:29 am
Tricked me. Drat.
Too bad I don't drink coffee....:crying:
Rob Schripsema
Propack, Inc.
August 7, 2012 at 10:47 am
Thomas Abraham (8/7/2012)
Thomas Abraham (8/7/2012)
+2 - This question has GOTCHA written all over it. While I admit I should have been more careful in reading the question, the question title and the way it changed the 45 to 50 seems purposefully designed to lead people to the conclusion that it's a rewritten/corrected reversion of last week's question. If your intent was to catch people not finely parsing the question, then you succeeded. (I can see the smirk on the OPs face when submitting the question.) At any rate, I do not like the spirit of the question.
I just went back and read last week's question and all the inputs the OP received. Given the spanking that question got, it seems like this is an attempt to stick a finger back in the eye of people that criticized the first question. So, explain to me why there isn't a little malice behind this question, even if the OP doesn't realize it.
I doubt this question is in regards to any discussion from the first question.
Questions are usually scheduled about a month in advance.
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
August 7, 2012 at 10:51 am
mtassin (8/7/2012)
And what happened to Steve's statement of NO MORE IMAGES for queries?Steve? Come on...
Not that it matters for this one... but it did look like a rewrite and fix of the original... I didn't even look closely at it.
This question was more than likely scheduled a month ago - long before the new mandate about images in questions.
I thought it was quite similar to the first but also noticed that the Select count(*) was changed to a Select *. That change alone eliminates any answer that has a 1 in it, even if you don't understand scope of table variables. 😀
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
August 7, 2012 at 11:50 am
SQLRNNR (8/7/2012)
I doubt this question is in regards to any discussion from the first question.
Questions are usually scheduled about a month in advance.
If that is indeed the case, then I apologize for seeing intent where there was none.
[font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
Connect to me on LinkedIn
Viewing 15 posts - 16 through 30 (of 51 total)
You must be logged in to reply to this topic. Login to reply