-2
現在我使光標更新爲2個表,並根據特定的select語句在一個表中插入此select語句返回2列x,yi需要x在表「PX」中更新,因爲x是此表中的主鍵並且需要x在表「FX」中更新,因爲x在此表中是外鍵,然後在第三個表中插入x數據。每個更新行的SQL插入語句
我需要改變這個遊標,並使用更新和插入腳本我試過,但我發現我需要做循環來實現我的目標,所以如果任何人知道我是否可以改變這個遊標。
而且由於事先
DECLARE @id int
DECLARE @clientid uniqueidentifier
DECLARE @code int
DECLARE @Wtime int
DECLARE @closeComplaint CURSOR
SET @closeComplaint = CURSOR FAST_FORWARD
FOR
SELECT ComplaintId, [ClientId]
FROM complaint
WHERE ComplaintStatusId = 5
AND (waitingForCutomerCloseDateTime < GETDATE() OR
waitingForCutomerCloseDateTime = GETDATE())
OPEN @closeComplaint
FETCH NEXT FROM @closeComplaint INTO @id, @clientid
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT
waitingForCutomerCloseTime = @Wtime
FROM
SystemConfiguration
WHERE
ClientId = @clientid
SELECT
[Code] = @code
FROM
[dbo].[resp_users]
WHERE
ClientId = @clientid
UPDATE activity
SET ActivityStatus = 4,
CompletionDate = GETDATE(),
ClosedBy = @code
WHERE [ComplaintId] = @id
UPDATE [dbo].[Complaint]
SET ComplaintStatusId = 2
WHERE [ComplaintId] = @id
INSERT INTO [dbo].[Note] ([Note_Description], [ClientId], [User_Code], [Visible_Internal],
[ComplaintId], [Note_DateTime], [ComplainantId],
[OneStopDesk_CustomerEmail], [OneStopDesk_CustomerUsername], [Private])
VALUES (N'Automatically closed by system after ' + @Wtime, @clientid, @code, 1,
@id, GETDATE(), null, null, null, 1)
FETCH NEXT FROM @closeComplaint INTO @id, @clientid
END
CLOSE @closeComplaint
DEALLOCATE @closeComplaint
沒有看到您的代碼,我們真的不能就如何修改它提出任何建議。編輯你的問題,幷包括代碼。 –
爲什麼你包含C#標籤?這看起來像一個純粹的SQL。 –
我添加了我的sql代碼@marc_s – NOOR