Is there a way to include go in dymanic SQL?
DECLARE @SQL VARCHAR(100)
DECLARE @dbName VARCHAR(100)--
SET @dbName = 'somedbname'--
SET @sql = 'USE [' + @dbName + ']' + CHAR(13) + CHAR(10)
SET @sql = @sql + 'GO' + CHAR(13) + CHAR(10)-- Print the command
EXEC (@sql)
When I run this it gives error Incorrect syntax near 'GO' has someone found workaround to this?
Requi开发者_如何转开发rement : I need to include stored procedure creation in switched database.
GO
is not a SQL statement - it is a command recognized by the SQL Server utilities (e.g. sqlcmd, osql, SQL Server Management Studio code editor).
However, you can change the database without the GO
command.
精彩评论