SQL Server 2008 中的以下存储过程引发错误
/****** Object: StoredProcedure [dbo].[UpdateCPA] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[pdateCPA_INT]
@CPAColumn_Name nvarchar(100), @value Int, @RecordNum nvarchar(100)
AS
BEGIN
SET NOCOUNT ON;
--declare @CPAColumn_Name nvarchar(100) = 'UsrsID'
--declare @value Int = 3575
--declare @RecordNum int = 1
declare @thedate smalldatetime
set @thedate = GETDATE()
--select @thedate as NOW
declare @cmd nvarchar(max)
set @cmd = 'Update tblTimeCPAReport
set ' + @CPAColumn_Name + ' = '+@value+'
set ReportLastUpdate = ' + @thedate + '
where RecordNum='+@RecordNum
exec sp_executesql @cmd
select @cmd
END
它抛出这个错误
将 nvarchar 值 'Update tblTimeCPAReport set UsrsID = ' 转换为数据类型 int 时转换失败。