2014-02-07 158 views
0

我需要編寫一個子查詢,它不允許我繼續。什麼是錯誤的以及如何實現這個目標?MS SQL相關的子查詢,無法寫入外部查詢

錯誤:「A」附近語法不正確。

SELECT * FROM 
(
    SELECT ID, 
     CAST([dbo].[SC_GetVersionedFieldValue](ID, '{25BED78C-4957-4165-998A-CA1B52F67497}') AS NVARCHAR(MAX)) AS '__Created', 
     CAST([dbo].[SC_GetVersionedFieldValue](ID, '{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}') AS NVARCHAR(MAX)) AS '__Updated' 
    FROM [dbo].[Items] WHERE [TemplateID] = '{8CB33CED-3E7E-4263-AF97-71B22338D9C7}'   
) mytable A WHERE exists (SELECT ID FROM mytable B WHERE A.ID = B.ID) ; 

回答

2

您應該刪除mytable和@harsh said刪除逗號。嘗試下面的代碼。

SELECT * FROM 
(
    SELECT ID, 
     CAST([dbo].[SC_GetVersionedFieldValue](ID, '{25BED78C-4957-4165-998A-CA1B52F67497}') AS NVARCHAR(MAX)) AS '__Created', 
     CAST([dbo].[SC_GetVersionedFieldValue](ID, '{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}') AS NVARCHAR(MAX)) AS '__Updated' 
    FROM [dbo].[Items] WHERE [TemplateID] = '{8CB33CED-3E7E-4263-AF97-71B22338D9C7}'   
) A 
    WHERE exists (SELECT ID FROM mytable B WHER A.ID = B.ID) ; 
3

FROM之前刪除逗號,很可能這是導致

+0

@harsh +1您的查詢具有良好抓 –

+0

''AS '__Updated',FROM' – harsh

+0

@harsh鷹派眼中的錯誤! 1 – Hoh