日期:2014-05-16  浏览次数:20469 次

Subqueries are not allowed in this context. Only scalar expressions are allowed.

我想获取表中某一列的最大值,然后插入到另外一个表中,报错的Sql如下:

insert into AA(AA_ID,AA_YWFSRQ) 
values
(NewID(),(  SELECT   CONVERT(varchar, DATEADD(day,- 1, CAST(SUBSTRING(MAX(YEB_RQ), 1, 4) 
                                    + SUBSTRING(MAX(YEB_RQ), 5, 2) + SUBSTRING(MAX(YEB_RQ), 7, 2) 
                                     AS datetime)), 112) FROM      YEB ));
修正:

insert into AA(AA_ID,AA_YWFSRQ) 
select
NewID(),(  SELECT   CONVERT(varchar, DATEADD(day,- 1, CAST(SUBSTRING(MAX(YEB_RQ), 1, 4) 
                                    + SUBSTRING(MAX(YEB_RQ), 5, 2) + SUBSTRING(MAX(YEB_RQ), 7, 2) 
                                     AS datetime)), 112) FROM      YEB )

错误提示信息:
        Subqueries are not allowed in this context. Only scalar expressions are allowed.

==》在此上下文中不允许使用子查询。只允许使用标量表达式。