Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem With Proc To Drop & Create Index
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Problem With Proc To Drop & Create Index
Miscellaneous
Thread ID:
01370489
Message ID:
01370489
Views:
55
I'm trying to create a sproc that drops & recreates an index:
DECLARE @TableName	nvarchar(100)
DECLARE @ColumnName	nvarchar(100)
DECLARE @IndexType  nvarchar(100)
DECLARE @IndexName	nvarchar(100)

SET @TableName	= 'AlertImport'
SET @ColumnName	= 'ContractNo'
SET @IndexType  = 'nonclustered'
SET @IndexName	= ''

IF @IndexName = ''
	SET @IndexName = 'IX_' + @ColumnName

IF EXISTS (SELECT name from sys.indexes WHERE name = @IndexName)
	EXEC('DROP INDEX ' + @IndexName + ' ON ' + @TableName + '.' + @ColumnName)

GO

EXEC ('CREATE ' + @IndexType + ' INDEX ' + @IndexName + ' ON ' + @TableName + '(' + @ColumnName) + ')'

GO
I'm getting the error 'Must declare the scalar variable "@IndexType'."

Double clicking the error puts me on the last line.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform