MS sql 语句的问题,过来看一下

来源:百度知道 编辑:UC知道 时间:2024/09/21 09:21:32
update spkfk set spbh='#'+spbh
from spkfk a,splsk b,spkfjc c
where a.spid=b.spid and b.spid=c.spid
and a.spbh not like '%#%'
and a.spbh not like '19%' and a.spbh not like '29%'
and a.spbh not like '44%' and a.spbh not like '59%'
and a.spbh not like '8144%'
and c.kcshl='0'
and a.spid=(select b.spid from splsk)

服务器: 消息 512,级别 16,状态 1,行 1
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
语句已终止。
一楼回答不对呀,运行后是这样的呀:

服务器: 消息 2601,级别 14,状态 3,行 1
不能在具有唯一索引 'spkfk_spbh' 的对象 'spkfk' 中插入重复键的行。
语句已终止。

赫赫,我是不知道你的具体逻辑,只不过根据你的错误给了一个解决方法。不行在换一个看看,在子查询中加上distinct,保证不返回重复值。
and a.spid = (select distinct b.spid from splsk)

子查询select b.spid from splsk返回的值多于一个,不能用=,可以改为in
and a.spid in (select b.spid from splsk)