Plz修复错误我的商店程序'@Created参数未提供'
问题描述:
错误:-Procedure或函数'spAddVoucherCheck'需要参数'@CreatedAt',这是未提供的。
我的商店 - p名称spAddVoucherCheck
Error:-Procedure or function 'spAddVoucherCheck' expects parameter '@CreatedAt', which was not supplied.
My store-p Name spAddVoucherCheck
ALTER PROC [dbo].[spAddVoucherCheck]
@xml xml,
@CreatedAt Varchar(200), @AccessBy int,
@error varchar(1000) output
AS
BEGIN
BEGIN TRY
DECLARE @MAXID as int;
SELECT @MAXID = ISNULL(MAX(ID), 0) FROM VoucherCheck;
INSERT INTO VoucherCheck(Title , CreatedAt ,CreatedOn,UpdatedOn,Status,CreatedBy,UpdatedBy,IPAddress
)
SELECT N.value('(Title)[1]', 'Varchar(MAX)') ,@CreatedAt,getdate(),getdate(),N.value('(Status)[1]', 'bit'),N.value('(CreatedBy)[1]', 'int'),N.value('(UpdatedBy)[1]', 'int'),N.value('(IPAddress)[1]', 'Varchar(50)') FROM @XML.nodes('/Table/VoucherCheck') as T(N);
DECLARE @SQL as Varchar(2000);
INSERT INTO VoucherCheckAccess (AccessAt, DataID, AccessBy)
SELECT @CreatedAt, T1.ID, @AccessBy FROM VoucherCheck T1 WHERE T1.ID > @MaxID;
END TRY
BEGIN CATCH
SET @Error = ERROR_NUMBER() + ' ' + ERROR_MESSAGE();
END CATCH
END
答
@CreatedAt是SP的输入参数,因此当您调用它时,您必须提供数据来填充它。当你创建SP时,不会发生错误,当你调用它时会发生这种错误。所以试试:
@CreatedAt is an input parameter to your SP, so when you call it you have to provide the data to fill it. The error doesn't occur when you creta ethe SP, it happens when you call it. So try:
EXEC dbo.spAddVoucherCheck @CreatedAt='Hello', ...
BTW:名称@CreatedAt暗示这是基于日期的数据:如果是这样,那么不要将其存储为NVARCHAR - 而是使用DATETIME字段 - 它会使您以后对数据执行的所有操作变得更加容易。因此,SP的@CreatedAt参数也应该是DATETIME。
BTW: the name @CreatedAt implies this is date based data: if so then don't store it as NVARCHAR - use a DATETIME field instead - it makes everything you do with the data later a lot, lot easier. As a result, the @CreatedAt parameter to your SP should be DATETIME as well.