Hi everyone!
Today's post is about an all too common problem... syntax issues.
Whether you fat-finger your keyboard or are always in a rush, chances are you have already encountered many syntax errors.
But if you are a newbie, your syntax error is just around the corner.
No worries, this is an easy fix.
Syntax errors just let you know part of your code or script is incorrect.
Scenario
I have a SQL agent job that is using the SQL command line to perform index maintenance, but it is failing.
Here's my code:
sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE dbo.IndexOptimize @Databases = 'databaseName', @FragmentationLow = NULL, @FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationLevel1 = 5, @FragmentationLevel2 = 30, @UpdateStatistics = 'ALL',@WaitAtLowPriorityMaxDuration = 180, @WaitAtLowPriorityAbortAfterWait = 'SELF', @OnlyModifiedStatistics = 'Y" -b
Here's the error message:
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string 'Y
'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Y
'.
Here's the fix:
At the end of the code add a ' after the letter Y.
Easy right?
Thank you and Happy reading,
-marshé hutchinson
#learnSQLwithme
Today's post is about an all too common problem... syntax issues.
Whether you fat-finger your keyboard or are always in a rush, chances are you have already encountered many syntax errors.
But if you are a newbie, your syntax error is just around the corner.
No worries, this is an easy fix.
Syntax errors just let you know part of your code or script is incorrect.
Scenario
I have a SQL agent job that is using the SQL command line to perform index maintenance, but it is failing.
Here's my code:
sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE dbo.IndexOptimize @Databases = 'databaseName', @FragmentationLow = NULL, @FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationLevel1 = 5, @FragmentationLevel2 = 30, @UpdateStatistics = 'ALL',@WaitAtLowPriorityMaxDuration = 180, @WaitAtLowPriorityAbortAfterWait = 'SELF', @OnlyModifiedStatistics = 'Y" -b
Here's the error message:
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string 'Y
'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Y
'.
Here's the fix:
At the end of the code add a ' after the letter Y.
Easy right?
If you have any further questions, please post below.
Thank you and Happy reading,
-marshé hutchinson
#learnSQLwithme
Comments
Post a Comment