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) + ')' GOI'm getting the error 'Must declare the scalar variable "@IndexType'."