我得到這個錯誤 Msg 102,Level 15,State 1,Procedure CostTest_02,Line 43 ';'附近語法不正確。SQL光標語法問題
以「GO」紅色下劃線我一直在尋找一段時間的錯誤,我找不到!我對遊標不是很有經驗(這是我寫的第一本)如果任何人都可以發現它或任何其他錯誤,我會非常感謝
http://imgur.com/9k40O < -----圖片是更多清晰(推薦)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE CostTest_02
AS
BEGIN
DECLARE @Issue_id int;
DECLARE @Master_id int;
DECLARE @Issue_table varchar(255);
DECLARE @price real;
DECLARE @rowcount bigint;
DECLARE cost_cursor cursor FOR
SELECT [Issue Id], [Master Id], [Issue Table], [Price]
from Adhoc_datafix..[Issue Table]
FOR UPDATE OF ADHOC_DATAFIX..[Issue Cost];
OPEN cost_cursor;
FETCH NEXT FROM cost_cursor into @Issue_ID, @Master_id, @Issue_table, @Price
WHILE @@FETCH_STATUS = 0
BEGIN
Select count(*) from @Issue_Table
set @Rowcount = @@rowcount
UPDATE ADHOC_DATAFIX..[Issue Cost]
set [Issue Id] = @Issue_ID ,
[Master Issue Id] = @Master_ID ,
[Row Count] = (Select count(*) from @Issue_Table), [email protected],
[Cost] = CAST(@Rowcount * @price as money)
WHERE CURRENT OF cost_cursor;
FETCH NEXT FROM cost_cursor
END
close cost_cursor;
DEALLOCATE cost_cursor;
GO
是的,這實際上幫了很多,但我仍然不確定兩種不同類型的FETCH,我肯定只需要一個FETCH ? – Callum
您需要同時提取,但它們都應該是'從cost_cursor下一步獲取@Issue_ID,@Master_id,@Issue_table,@ Price'。第一次獲取獲得第一個匹配的行並設置了初始的「fetch_status」,即是否找到了某個東西。在每次循環之後,再次調用fetch來嘗試獲取另一行並更新'fetch_status'。 – Rhumborl
非常感謝!那就是我想要的只是需要確認 – Callum