ALTER proc [dbo].[p_query]( @start int, @end int)asbegin declare @viewName nvarchar(32) declare @sql nvarchar(256) select @viewName =viewName from T_viewSelect where dataMin<@start and dataMax>@end and dataMax >@start set @sql='select * from '+@viewName set @sql=@sql+ ' where id >'+cast(@start as nvarchar) set @sql=@sql+'and id< '+cast(@end as nvarchar) print @sql exec(@sql)end
需要将声明的@start int类型的转换为字符串加到定义的@sql的这个字符穿中