EXECUTE

  • Comments posted to this topic are about the item EXECUTE

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Nice back to basics question -- no gimmicks .... nice very nice

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Nice question. Thanks

    Thanks

  • Great question, thanks Henrico.

    I stumbled across this issue a few times too many, so a real easy one for me 🙂

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (2/14/2012)


    Great question, thanks Henrico.

    I stumbled across this issue a few times too many, so a real easy one for me 🙂

    You're not alone, Koen 😛

    --------------------------------------------------------------------------
    A little knowledge is a dangerous thing (Alexander Pope)
    In order for us to help you as efficiently as possible, please read this before posting (courtesy of Jeff Moden)[/url]

  • Good question - i got it right.

    But surely without running the code there would be no output :0)

    (Above is tongue in cheek)

  • danielfountain (2/14/2012)


    But surely without running the code there would be no output :0)

    Indeed! :w00t:

    I'm missing the answer "after waiting for a few hours you eventually decide to go home..."

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I would have expected it to fail due to no newline or semicolon.

    But it were not so

    Anywhere I can find specific rules about when to use and when not to use semicolon?

    Except the reserved word ";with" of course.

  • kll 51891 (2/14/2012)


    I would have expected it to fail due to no newline or semicolon.

    But it were not so

    Anywhere I can find specific rules about when to use and when not to use semicolon?

    Except the reserved word ";with" of course.

    The semicolon is not yet obligated, except when using the WITH clause. This probably will change in a future version.

    If there's a statement before the WITH clause, it should be terminated with a semicolon. Pay attention, this is not the same as saying that it should be ";WITH". If everyone starts terminating statements with semicolon in old code to make the code portable to a newer edition of SQL Server, all ;WITH statements will fail.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (2/14/2012)


    kll 51891 (2/14/2012)


    I would have expected it to fail due to no newline or semicolon.<snip>

    The semicolon is not yet obligated, except when using the WITH clause. This probably will change in a future version.

    If there's a statement before the WITH clause, it should be terminated with a semicolon. Pay attention, this is not the same as saying that it should be ";WITH". If everyone starts terminating statements with semicolon in old code to make the code portable to a newer edition of SQL Server, all ;WITH statements will fail.

    Thank you for the clarification.

    A quick test:

    use master

    select top 10 * from sys.all_columns

    select top 10 * from sys.all_objects

    select top 10 * from sys.all_columns select top 10 * from sys.all_objects

    select top 10 * from sys.all_columns ;; select top 10 * from sys.all_objects

    reveals that you are correct in the missing semicolons are OK. But it doesn't show why an abundance of semicolons should have detrimental effects.

    My quoting of ";with" were somewhat tongue-in-cheek as it is the first keyword that I am aware of that doesn't accept a newline as a break in command.

    Anyway, looking objectively at stuff, then the fact that I can write

    Select *

    From xx

    Where something is right

    should warn me that semicolons were problably superflous.

  • Koen Verbeeck (2/14/2012)


    kll 51891 (2/14/2012)


    I would have expected it to fail due to no newline or semicolon.

    But it were not so

    Anywhere I can find specific rules about when to use and when not to use semicolon?

    Except the reserved word ";with" of course.

    The semicolon is not yet obligated, except when using the WITH clause. This probably will change in a future version.

    If there's a statement before the WITH clause, it should be terminated with a semicolon. Pay attention, this is not the same as saying that it should be ";WITH". If everyone starts terminating statements with semicolon in old code to make the code portable to a newer edition of SQL Server, all ;WITH statements will fail.

    Most of the above is true.

    Terminiating SQL statements with a semicolon has always been allowed in SQL Server, but it was optional. WITH was the first keyword (but is not the only one) that requires the statement before it (if any) to be semicolon-terminated, otherwise the parser would think that the WITH keyword was for query hints. It has already been announced that in some future version, omitting the semicolon will be disallowed in all cases. There has not been any mention as to which version that will be. But it's a good idea to start getting into the habit now of always using the semicolon statement terminator.

    I consider the use of ;WITH a bad habit, as it works around one limitation while not addressing the true underlying issue. And it will come back to bite you when terminating is no longer optional. However, it does currently work - not because he parser accepts prepending WITH with a semicolon as a viable alternative, but because the parser ignores whitespace and line breaks - so it "sees" the semicolon right after the end of the preceding statement and interprets it as a statement terminator.

    However, it is not true that ;WITH will cause errors when all statements are semicolon terminated. There is no limit to how many semicolons you use and where you place them. The code below, though clearly not recommended coding style, works.

    SELECT 1;;;

    ;;;

    ;;;WITH x AS (SELECT 1 AS a)

    SELECT * FROM x


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Thanks for the great question. Couple points:

    1. I thought both statements were exactly the same. I sat there looking at it for about 4 minutes before I noticed the difference between the two. I must be going blind.

    2. Technically, both statements could execute if you just happened to have a stored procedure with the name [use master dbcc showfilestats]. I know, this is crazy but did want to be the first to mention it 🙂

  • cengland0 (2/14/2012)


    Technically, both statements could execute if you just happened to have a stored procedure with the name [use master dbcc showfilestats]. I know, this is crazy but did want to be the first to mention it 🙂

    I'm sorry, but you are too late. Henrico already covered that crazy possibility in the explanation of the question: "SQL will assume '@sqlstring' is a Stored Procedure and will fail, assuming it doesn't exist." (emphasis mine)

    😀


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Hugo Kornelis (2/14/2012)


    cengland0 (2/14/2012)


    Technically, both statements could execute if you just happened to have a stored procedure with the name [use master dbcc showfilestats]. I know, this is crazy but did want to be the first to mention it 🙂

    I'm sorry, but you are too late. Henrico already covered that crazy possibility in the explanation of the question: "SQL will assume '@sqlstring' is a Stored Procedure and will fail, assuming it doesn't exist." (emphasis mine)

    😀

    Gee thanks. You had to ruin my fun didn't you? 😉

  • good question!!!

    thanks!


    [font="Times New Roman"]rfr.ferrari[/font]
    DBA - SQL Server 2008
    MCITP | MCTS

    remember is live or suffer twice!
    the period you fastest growing is the most difficult period of your life!

Viewing 15 posts - 1 through 15 (of 49 total)

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