我修改了一个存储过程,并添加了一个额外的参数添加到表中。问题是添加的参数的值与原始参数交换。
ALTER PROCEDURE [dbo].[spWeb_BulkGenerateWRsDevices]
(
@WorkRequestDeviceId nvarchar(max) = NULL,
@TechnicianId int = NULL,
@RequiredBy datetime = NULL,
@Priority int = NULL,
@WRTypeId int,
@WorkRequestSummary nvarchar(255) = NULL,
@AuthorOfRequest int,
@Contact nvarchar(40) = NULL,
@PhoneNo nvarchar(20) = NULL,
@StatusId int,
@Created datetime = NULL,
@CustomerId int
)
AS
/* Update the WR record */
BEGIN
DECLARE @COUNT INT
SET @COUNT =(SELECT COUNT(*) FROM WorkRequest WHERE WorkRequestDeviceId IN(SELECT stringval FROM dbo.CSV(@WorkRequestDeviceId)))
IF @COUNT >0
BEGIN
DECLARE @InsertedRows AS TABLE (WorkRequestId int,WorkRequestDeviceId int)
INSERT INTO WorkRequest
(AllocatedTo,RequiredBy,Priority,WRTypeId,WorkRequestSummary,AuthorOfRequest,
Contact,PhoneNo,StatusId,DateOfRequest,WorkRequestDeviceId,CustomerId)
OUTPUT Inserted.WorkRequestId,Inserted.WorkRequestDeviceId INTO @InsertedRows
SELECT @TechnicianId ,@RequiredBy,@Priority,@WRTypeId,@WorkRequestSummary,@AuthorOfRequest,@Contact
,@PhoneNo,@StatusId,@Created,@CustomerId,* from dbo.fnSplit(@WorkRequestDeviceId, ',')
END
IF @COUNT = 0
BEGIN
INSERT INTO WorkRequest
(WorkRequestDeviceId)
SELECT * from dbo.fnSplit(@WorkRequestDeviceId, ',')
UPDATE WorkRequest
SET
AllocatedTo =@TechnicianId ,
RequiredBy = @RequiredBy,
Priority = @Priority,
WRTypeId = @WRTypeId,
WorkRequestSummary =@WorkRequestSummary,
AuthorOfRequest= @AuthorOfRequest,
Contact = @Contact,
PhoneNo = @PhoneNo,
StatusId = @StatusId,
DateOfRequest = @Created,
CustomerId = @CustomerId
WHERE WorkRequestDeviceId IN(SELECT stringval FROM dbo.CSV(@WorkRequestDeviceId))
END
我添加了CustomerId参数。当我调用该过程并说设置WorkRequestDeviceId = 312和CustomerId = 148时,表WorkRequest有一条新记录,但WorkRequestDeviceId = 148和CustomerId = 312.我是存储过程的新手,所以对不起我的无知,任何想法? 詹姆斯
答案 0 :(得分:0)
您的插入是在insert语句和select中转换变量。
将插入内容更改为:
INSERT INTO WorkRequest
(AllocatedTo,RequiredBy,Priority,WRTypeId,WorkRequestSummary,AuthorOfRequest,
Contact,PhoneNo,StatusId,DateOfRequest,CustomerId,WorkRequestDeviceId)
一切都应该没问题。