Dynamic SQL Execution
Im开发者_C百科 not able to execute below query.Please help.
Declare @i Int
Set @i=1
Exec ('Create index tind'+convert(varchar(20),@i)+ ' on product(qty)')
You can't have an expression as the EXEC argument. Do the dynamic SQL first
Declare @i Int, @sql varchar(1000)
Set @i=1
Set @sql = 'Create index tind'+convert(varchar(20),@i)+ ' on product(qty)'
Exec (@sql)
精彩评论