MS SQL相关子查询,无法编写外部查询

时间:2014-02-07 11:03:30

标签: sql sql-server

我需要编写一个子查询,它不允许我继续。有什么不对,怎么做到这一点?

错误:'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 个答案:

答案 0 :(得分:3)

FROM之前删除逗号,很可能是导致错误

答案 1 :(得分: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) ;