在SQL Server 2008下面的存储过程中抛出一个错误SQL Server存储过程的参数的数据类型的错误
/****** 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 + ' = '[email protected]+'
set ReportLastUpdate = ' + @thedate + '
where RecordNum='[email protected]
exec sp_executesql @cmd
select @cmd
END
它抛出这个错误转换nvarchar的值时
转换失败“更新 tblTimeCPAReport设置UsrsID ='为数据类型int。
好吧,所以我实际上不必为每个数据类型设置不同的SP,因为它根据值类型和数据库容器为它自己找出了一个文本句子,确保我没有“违反规则”,这就是它所需要的。 @ – LoneXcoder
@LoneXcoder你可以以正确的格式传递数据类型,但是当你将它添加到你的'@ cmd'时,它将需要与那个变量相同的数据类型,否则它将不兼容 – Taryn
我希望你不介意它仍然抛出一个错误,虽然我已经解决了更复杂的问题然后这个简单的我不能把我的手指放在哪里出错我会更新我的问题请按照 – LoneXcoder