获取错误:子查询返回的值超过1

时间:2013-10-22 08:18:46

标签: sql sql-server-2008

以下是我的SQL查询

BEGIN TRAN

DECLARE @PRE_CD INT = (SELECT ISNULL(MAX(PRE_CD), 0) FROM  TBL_MAIN)

INSERT INTO TBL_MAIN
            (PRE_CD,
             PRE_DESC,
             PRE_REF_CD)
SELECT ROW_NUMBER() OVER (ORDER BY PRESENTATION) + @PRE_CD,
       PRESENTATION,
       3
FROM   (SELECT DISTINCT PRESENTATION
        FROM   Temp_Data
        WHERE  PRESENTATION NOT IN (SELECT PRE_DESC
                                    FROM   TBL_MAIN)) T

COMMIT; 

执行此查询时出现错误

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

1 个答案:

答案 0 :(得分:0)

我没有看到代码可以直接导致它。

可能你在表上有一个错误的INSERT触发器,它假定INSERTED只包含一行而且多行插入失败。