首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql update 有关问题。纠结了好久了。大侠们帮帮忙。

2012-02-09 
sql update 问题。。。纠结了好久了。。。大侠们帮帮忙。。-----select t2.fbillno,t1.fentryid_src,t2.fitemidfro

sql update 问题。。。纠结了好久了。。。大侠们帮帮忙。。
-----
select t2.fbillno,t1.fentryid_src,t2.fitemid
from t_sz_wkorderentry t1,t_sz_wkorder t2 ,seorderentry t3
where t1.fid = t2.fid and t2.fitemid=t3.fitemid and t1.fentryid_src=t3.fentryid
---这段代码执行结果:

fbillno fentryid fitemid
00000029 1 1907
00000036 1 1893
00000037 2 1905
00000038 3 1907
00000039 4 1909
00000040 5 1911
00000041 6 1915
00000042 1 1919

----另外一个表查询结果

select fentryid,fitemid, FEntrySelfS0168 from seorderentry

----结果:
fentryid fitemid FEntrySelfS0168
1 1907 
1 1893 
2 1905 
3 1907 
4 1909 
5 1911 
6 1915 
1 1919 99990
---我用这个语句执行更改时提示错误
update mm set FEntrySelfS0168= b.fbillno
from seorderentry mm inner join  
(select t2.fbillno,t1.fentryid_src,t2.fitemid
from t_sz_wkorderentry t1,t_sz_wkorder t2 ,seorderentry t3
where t1.fid = t2.fid and t2.fitemid=t3.fitemid and t1.fentryid_src=t3.fentryid ) b  
on mm.fentryid = b.fentryid_src and mm.fitemid = b.fitemid
-----错误提示:
消息 512,级别 16,状态 1,过程 bb,第 5 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
语句已终止。


大侠们帮忙弄一下看。。。。具体错在什么地方了。
纠结了好久了。。。



[解决办法]
没问题吧,应该能运行:

SQL code
create table t(fbillno varchar(10),fentryid_src int,fitemid int)insert into t select '00000029',1,1907insert into t select '00000036',1,1893insert into t select '00000037',2,1905insert into t select '00000038',3,1907insert into t select '00000039',4,1909insert into t select '00000040',5,1911insert into t select '00000041',6,1915insert into t select '00000042',1,1919create table seorderentry(fentryid int,fitemid int,FEntrySelfS0168 int)insert into seorderentry select 1,1907,nullinsert into seorderentry select 1,1893,nullinsert into seorderentry select 2,1905,nullinsert into seorderentry select 3,1907,nullinsert into seorderentry select 4,1909,nullinsert into seorderentry select 5,1911,nullinsert into seorderentry select 6,1915,nullinsert into seorderentry select 1,1919,99990goupdate mm set FEntrySelfS0168= b.fbillnofrom seorderentry mm inner join   (select * from t) b   --用这个查询结果代替你的查询语句on mm.fentryid = b.fentryid_src and mm.fitemid = b.fitemidselect * from seorderentry/*fentryid    fitemid     FEntrySelfS0168----------- ----------- ---------------1           1907        291           1893        362           1905        373           1907        384           1909        395           1911        406           1915        411           1919        42(8 行受影响)*/godrop table t,seorderentry 

热点排行
Bad Request.