Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem With Proc To Drop & Create Index
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Problem With Proc To Drop & Create Index
Divers
Thread ID:
01370489
Message ID:
01370489
Vues:
58
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform