Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Execuate SQL Task - not recognize "go"

Author  Topic 

heliang
Starting Member

38 Posts

Posted - 2015-01-21 : 13:09:25
I am trying to run multiple SQL statement as following

drop index XXX on XX
go
drop index XXX on XX
go
drop index XXX on XX
go

but it does not recognize "go" and will not go to the second statement if the first index does not exist. What am I missing?

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-21 : 13:12:29
GO isn't T-SQL syntax. It is a batch separator for things like sqlcmd and a query window in SSMS. You could use multiple execute SQL tasks. Or you could wrap the code in a stored procedure. Or you could try passing the whole thing into sp_executesql.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-28 : 09:40:49
use the below code
IF EXISTS(SELECT * FROM SYS.INDEXES
WHERE OBJECT_NAME(OBJECT_ID)= 'TableName'
AND NAME='IndexName'
)
DROP INDEX xxx ON xx

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -