当前命令发生严重错误。 - 未知错误

时间:2014-04-01 12:48:04

标签: sql-server common-table-expression

这是我的代码。

;With CTE as
(
select
    a.rn,
    a.LongDescription as ad,
    b.LongDescription as bd
from myTabl as a
    left join myTabl as b on a.rn +1 = b.rn
where
    a.rn=1
and
    a.LongDescription = 'Eric'
)
update CTE
    set ad += ' ' + b.LongDescription
from CTE as a
    left join myTabl as b on a.rn = b.rn+1
where
    a.rn=1

我试图回答一个问题,同时尝试差异。我遇到错误的选项,

Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command.  The results, if any, should be discarded.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command.  The results, if any, should be discarded.

这是什么,我什么都没得到。我的代码中有任何重大错误吗?我试图谷歌它,但所有结果都将我重定向到#34; Microsoft Fix"。有人可以用简单的话来解释我的错误吗?

2 个答案:

答案 0 :(得分:0)

我想你需要改变设定线:

set ad = a.ad + ' ' + b.LongDescription

检查SQL小提琴演示here

答案 1 :(得分:0)

尝试这.................

;With CTE as
(
select
    a.rn,
    a.LongDescription as ad,
    b.LongDescription as bd
from myTabl as a
    left join myTabl as b on a.rn +1 = b.rn
where
    a.rn=1
and
    a.LongDescription = 'Eric'
)
update CTE
    set ad += ' ' + b.LongDescription
from CTE as a
    left join 
    ( select (rn+1) AS NewRN,* from myTabl )as b on a.rn = b.NewRN
where
    a.rn=1