2013-07-17 161 views
0
BEGIN 
OPEN DQC_Cursor1 ; 
LOOP 

FETCH DQC_Cursor1 INTO @table_name1 ; 
EXIT when DQC_Cursor1%notfound; 
EXEC Incorporate @table_name = @table_name1, 
    @historical_table_name = Replace(
     @table_name1, 
     'Temp', 
     'Historical' 
    ) ; 

END EXEC; 
END LOOP; 


CLOSE DQC_Cursor1; 
commit; 
END; 

我得到的錯誤消息如下。我也接近不正確的語法;,當我將鼠標懸停在帶下劃線的錯誤上時,期待對話。我已經寫入了已經存儲的存儲過程。任何人都知道這裏出了什麼問題?有人知道這裏有什麼問題嗎?

Incorrect syntax near 'LOOP'. 
Incorrect syntax near the keyword 'EXIT'. 
+0

您使用的是哪種數據庫引擎? –

+0

我正在使用MSSQL – user2456195

+0

請爲您的問題設計一個更有意義的標題。你的代碼縮進是不穩定或異乎尋常的;它不容易閱讀。錯誤消息中的行號與您所顯示的SQL有任何關係並不明顯 - 例如,在第3行附近沒有LOOP。這種不匹配是如何發生的? –

回答

1

我假設Incorporate是你有的存儲過程。正如評論所暗示的那樣,你的遊標語法有點混亂,並且通過documentation讀取會有很大幫助。但在這種情況下,請嘗試:

declare @table_name1 varchar(max); 

declare DQC_Cursor1 cursor 
for 
    select Table_Name 
    from TableNames; 

open DQC_Cursor1 
fetch next from DQC_Cursor1 into @table_name1 
while @@FETCH_STATUS = 0 
    begin 
     exec Incorporate @table_name = @table_name1, 
       @historical_table_name = replace(@table_name1,'Temp','Historical') 
    end 
close DQC_Cursor1; 
deallocate DQC_Cursor1; 
+0

謝謝,我認爲這個工程 – user2456195

相關問題