Create a stored procedure

  • JaimePC

    SSC Eights!

    Points: 864

    Comments posted to this topic are about the item Create a stored procedure

  • happycat59

    One Orange Chip

    Points: 29189

    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]).

  • Vimal Lohani

    SSCommitted

    Points: 1650

    happycat59 (10/14/2014)


    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]).

    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

  • saravanan.a 88885

    SSC Eights!

    Points: 993

    Yes happycat59 I got the Same Error......:hehe:

  • gysev1207

    SSC Veteran

    Points: 221

    same error:crazy:

  • Vimal Lohani

    SSCommitted

    Points: 1650

    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

  • Mauricio_

    SSCrazy

    Points: 2931

    Same error: Msg 156, Level 15, State 1, Procedure my_sp, Line 2

    Incorrect syntax near the keyword 'FROM'.

  • Carlo Romagnano

    SSC-Insane

    Points: 21948

    happycat59 (10/14/2014)


    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]).

    +1

    Please, before you submit a qotd, run a minimal test!

  • Mauricio_

    SSCrazy

    Points: 2931

    By the way, no error if you use this syntax:

    CREATE PROCEDURE my_sp AS

    SELECT [column] FROM my_table

  • radek.hruby

    SSCrazy

    Points: 2123

    That's what probably the author meant but it doesn't change the fact that the query as provided returns an error.

  • Neil Burton

    SSC-Insane

    Points: 22188

    Mauricio N (10/15/2014)


    Same error: Msg 156, Level 15, State 1, Procedure my_sp, Line 2

    Incorrect syntax near the keyword 'FROM'.

    +1


    On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" ... I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
    —Charles Babbage, Passages from the Life of a Philosopher

    How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537

  • paul.knibbs

    SSCoach

    Points: 15270

    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.

  • Mauricio_

    SSCrazy

    Points: 2931

    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.

  • Toreador

    SSChampion

    Points: 11253

    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

  • Neil Burton

    SSC-Insane

    Points: 22188

    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.


    On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" ... I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
    —Charles Babbage, Passages from the Life of a Philosopher

    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 65 total)

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