在使用存储过程时,若动态的传递表名或者是列名时,可以考虑使用动态sql。代码如下;
alter procedure Proc_UpdateDatetimeCounter
@businessNum nvarchar( 200),--业务号
@column nvarchar( 200),--列名
@value datetime--值
as
declare @sql nvarchar(max)
set @sql = N ' update counter set '+quotename(@column)+ ' = @value1 where businessNum = @businessNum1 '
exec sp_executesql @sql,
N ' @value1 as datetime,@businessNum1 as nvarchar(200) ',
@value1 = @value,
@businessNum1 = @businessNum