April 30, 2009 at 8:38 pm
Comments posted to this topic are about the item Dynamic Query
May 1, 2009 at 7:35 am
Hi,
I ran given queries. and got only 2 and 3 are display result TEST.
none of the other display any "TEST" some of displya Command Executed Successfully.
DECLARE @query AS VARCHAR(20)
DECLARE @variable AS VARCHAR(5)
SELECT @variable = 'TEST' --> Command(s) completed successfully.
--1
SELECT @query = 'SELECT ''TEST'' ' -->TEST
EXEC (@query)
--2
SELECT @query = 'SELECT ' + '''TEST''' -->TEST
EXEC (@query)
--3
SELECT @query = 'SELECT ' + @variable -->Missing end comment mark '*/'.
EXEC (@query)
--4
SELECT @query = 'SELECT ' + '''' + @variable + '''' --> Command(s) completed successfully.
EXEC (@query)
--5
SELECT @query = 'SELECT ' + ''' + @variable + ''' Unclosed quotation mark after the character string ' + @variable'.
EXEC (@query)
Only 2 and 3 is the right answer
[font="Arial Black"]Navi's:-)[/font]
May 1, 2009 at 7:49 am
Navi's (5/1/2009)
Hi,DECLARE @query AS VARCHAR(20)
DECLARE @variable AS VARCHAR(5)
SELECT @variable = 'TEST' --> Command(s) completed successfully.
Only 2 and 3 is the right answer
SELECT @variable = 'TEST' is the value passed in variable.
Answer is right for question. 1,2,4 are correct answers.
Error on 3:
Msg 207, Level 16, State 1, Line 1
Invalid column name 'TEST'.
Error on 5:
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string ' + @variable'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ' + @variable'.
SQL DBA.
May 1, 2009 at 8:03 am
Ohh!! got my mistake...
Thanks
[font="Arial Black"]Navi's:-)[/font]
May 1, 2009 at 8:25 am
Far too easy!
Since 1 works, the answer had to include 1. Hence it had to be 1,2,4 without needing to actually check the others. 🙂
Derek
May 1, 2009 at 8:25 am
I found this Q too easy, as option 1 seemed correct and was listed in only one of the five possible answers for the Q, but I looked at the other options just to satisfy myself that options 2 and 4 were also correct :-).
May 1, 2009 at 8:41 am
If you modify the code for the Select variable as follows.
SELECT @variable = '''TEST'''
Then 1,2,3 works and not 4 and 5
May 3, 2009 at 6:19 pm
Feel cheated by this one, as the question should have been a 'Choose all that apply'. Making it multi-choice makes the answer obvious. This is really annoying when you have actually bothered to work out the correct options first!
May 4, 2009 at 12:03 am
Very Tricky...
The last query DO NOT Execute due to the the @query variable declared as varchar(20)
if You declare the @query variable as varchar(25), it executes.
Nice...
May 4, 2009 at 2:47 am
Atif Sheikh (5/4/2009)
Very Tricky...The last query DO NOT Execute due to the the @query variable declared as varchar(20)
if You declare the @query variable as varchar(25), it executes.
Nice...
It'll execute all right, but it'll NOT produce the requested result...
May 4, 2009 at 3:05 am
Oh Yes... You are absolutely Right...
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply