October 14, 2014 at 9:14 pm
Comments posted to this topic are about the item Create a stored procedure
October 14, 2014 at 9:18 pm
I get error
Msg 156, Level 15, State 1, Procedure my_sp, Line 2
Incorrect syntax near the keyword 'FROM'.
because "Column" is a reserved keyword and needs to be delimited if you want to use it as a column (e.g. [Column]).
October 14, 2014 at 10:38 pm
happycat59 (10/14/2014)
I get errorMsg 156, Level 15, State 1, Procedure my_sp, Line 2
Incorrect syntax near the keyword 'FROM'.
because "Column" is a reserved keyword and needs to be delimited if you want to use it as a column (e.g. [Column]).
You are right,
Given answer is wrong, although syntax is right, Still Sql server will give error on given procedure.
Admin should review once again.
Vimal LohaniSQL DBA | MCP (70-461,70-462)==============================The greatest barrier to success is the fear of failure ** Success is a journey not a destination**Think before you print, SAVE TREES, Protect Mother Nature
October 14, 2014 at 11:00 pm
Yes happycat59 I got the Same Error......:hehe:
October 14, 2014 at 11:14 pm
same error:crazy:
October 15, 2014 at 12:31 am
The answer is right for this kind of procedure :
CREATE PROCEDURE my_sp AS
SELECT id FROM my_table
The answer is Wrong for below procedure
CREATE PROCEDURE my_sp AS
SELECT Column FROM my_table
Vimal LohaniSQL DBA | MCP (70-461,70-462)==============================The greatest barrier to success is the fear of failure ** Success is a journey not a destination**Think before you print, SAVE TREES, Protect Mother Nature
October 15, 2014 at 1:10 am
Same error: Msg 156, Level 15, State 1, Procedure my_sp, Line 2
Incorrect syntax near the keyword 'FROM'.
October 15, 2014 at 1:11 am
happycat59 (10/14/2014)
I get errorMsg 156, Level 15, State 1, Procedure my_sp, Line 2
Incorrect syntax near the keyword 'FROM'.
because "Column" is a reserved keyword and needs to be delimited if you want to use it as a column (e.g. [Column]).
+1
Please, before you submit a qotd, run a minimal test!
October 15, 2014 at 1:12 am
By the way, no error if you use this syntax:
CREATE PROCEDURE my_sp AS
SELECT [column] FROM my_table
October 15, 2014 at 1:22 am
That's what probably the author meant but it doesn't change the fact that the query as provided returns an error.
October 15, 2014 at 1:26 am
Mauricio N (10/15/2014)
Same error: Msg 156, Level 15, State 1, Procedure my_sp, Line 2Incorrect syntax near the keyword 'FROM'.
+1
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
October 15, 2014 at 1:58 am
Maybe the author chose the column name deliberately to catch out people who just run the SQL rather than thinking about their answer? I mean, the error about incorrect syntax near "FROM" isn't one of the available answer options, so it should be pretty obvious that's not what was intended.
October 15, 2014 at 2:08 am
paul.knibbs (10/15/2014)
Maybe the author chose the column name deliberately to catch out people who just run the SQL rather than thinking about their answer? I mean, the error about incorrect syntax near "FROM" isn't one of the available answer options, so it should be pretty obvious that's not what was intended.
Yes, it is, none of the above.
October 15, 2014 at 2:09 am
paul.knibbs (10/15/2014)
I mean, the error about incorrect syntax near "FROM" isn't one of the available answer options, so it should be pretty obvious that's not what was intended.
It would be covered by the "none of the above" option
October 15, 2014 at 2:11 am
paul.knibbs (10/15/2014)
Maybe the author chose the column name deliberately to catch out people who just run the SQL rather than thinking about their answer? I mean, the error about incorrect syntax near "FROM" isn't one of the available answer options, so it should be pretty obvious that's not what was intended.
That argument doesn't really hold water though. I'm sure some of the big (and not so big) hitters will be able to look at that code and see that it won't run without a second thought. The incorrect syntax error is implicitly one of the options because 'None of the Above' is a choice.
I tend to look at the question and depending on what it's about, either answer it straightaway, pick an option that I think is right then run the code to confirm it or go off and research. In this case I actually chose the correct option initially but when I ran the code and got an error I changed my answer and got it wrong.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
Viewing 15 posts - 1 through 15 (of 64 total)
You must be logged in to reply to this topic. Login to reply