August 23, 2013 at 12:22 pm
Hi,
I am a complete beginner developing with MSSQL.
I have just created my first stored procedure in Visual Studio. If I try to use the keyword 'GO', I get a syntax error. If I save the stored procedure and then view it in Microsoft SQL Management Studio using the 'Modify' menu selection, I get a query windows which has added extra stuff before my stored procedure and also makes use of the keyword 'GO'.
I am trying to create a table and then add some data to it. The INSERT fails, and I was thinking it might be because I had not put 'GO' between the CREATE TABLE and the INSERT, but, as I said, Visual Studio won't let me do this.
I'm obviously being a bit thick about something here. Any help would be gratefully received.
Kind wishes, Patrick
August 23, 2013 at 12:41 pm
patrickskelton (8/23/2013)
Hi,I am a complete beginner developing with MSSQL.
I have just created my first stored procedure in Visual Studio. If I try to use the keyword 'GO', I get a syntax error. If I save the stored procedure and then view it in Microsoft SQL Management Studio using the 'Modify' menu selection, I get a query windows which has added extra stuff before my stored procedure and also makes use of the keyword 'GO'.
I am trying to create a table and then add some data to it. The INSERT fails, and I was thinking it might be because I had not put 'GO' between the CREATE TABLE and the INSERT, but, as I said, Visual Studio won't let me do this.
I'm obviously being a bit thick about something here. Any help would be gratefully received.
Kind wishes, Patrick
Are you trying to create a table in your stored proc? You should create the table outside of a stored proc. Then use your stored proc for the insert.
The word GO is only a batch separator in SSMS. It is not a valid t-sql command. In other words if you create a proc and the batch separator is in the body it will actually end the proc when it encounters GO even if there is more text afterwards.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 23, 2013 at 12:42 pm
"GO" is not a T-SQL command, that's a Microsoft's stuff. You use GO to create batches inside your T-SQL code but you should not use it inside an store procedure as an store procedure itself is a single unit of several T-SQL commands.
When writing T-SQL code, you should end each statement with the command terminator, which is the semicolon (;).
If you want to separate code inside your store procedure, use BEGIN ... END ...
August 24, 2013 at 3:05 am
I see. Thank you for those replies. Got it working now.
(Now I only have 1,999,999 questions still to ask. Into the forums, I think.)
Kind wishes ~ Patrick
August 25, 2013 at 1:57 pm
patrickskelton (8/24/2013)
I see. Thank you for those replies. Got it working now.(Now I only have 1,999,999 questions still to ask. Into the forums, I think.)
Kind wishes ~ Patrick
Glad you got it sorted out. The forums are a great place to ask questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply