关于存储过程
表tbbom2
ID prodno fno cno num lvl
12 HY50-7 HY50-7 HY50-7 1.0000 0
13 HY50-7 12 0010010034 1.0000 1
14 HY50-7 12 0010010035 1.0000 1
45 QKS18 QKS18 QKS18 1.0000 0
46 QKS18 45 0010010034 1.0000 1
47 QKS18 45 0010010035 2.0000 1
48 QKS18 45 0010010036 3.0000 1
49 QKS18 45 0010010037 4.0000 1
50 QKS18 45 0010010038 5.0000 1
51 QKS18 45 0010010039 6.0000 1
32 0209-3-2 0209-3-2 0209-3-2 1.0000 0
53 QKS18 45 0010010041 8.0000 1
表tmp_bom2
ID prodno fno cno num lvl
46 QKS18 45 0010010034 1.0000 1
47 QKS18 45 0010010035 2.0000 1
48 QKS18 45 0010010036 3.0000 1
49 QKS18 45 0010010037 4.0000 1
50 QKS18 45 0010010038 5.0000 1
53 QKS18 45 0010010041 8.0000 1
存储过程:updatetbbom2
CREATE PROCEDURE updatetbbom2
@prodno varchar,
@tmplvl numeric(18,0)
AS
delete from tbbom2 where prodno=@prodno and fno+cno+cast(lvl as varchar(50)) not in
(select fno+cno+cast(lvl as varchar(50)) from tmp_bom2) and lvl=@tmplvl
update tbbom2 set fno=tmp_bom2.fno,
cno=tmp_bom2.cno,num=tmp_bom2.num,bz=tmp_bom2.bz
from tmp_bom2 where tbbom2.fno=tmp_bom2.fno and tbbom2.cno=tmp_bom2.cno and tbbom2.lvl=tmp_bom2.lvl
insert into tbbom2
(prodno,fno,cno,num,lvl,bz)
select prodno,fno,cno,num,lvl,bz from tmp_bom2
where fno+cno+cast(lvl as varchar(10)) not in
(select fno+cno+cast(lvl as varchar(10)) from tbbom2)
我在查询分析器中执行:
exec updatetbbom2 'QKS18 ',1
返回结果
(所影响的行数为 0 行)
(所影响的行数为 6 行)
(所影响的行数为 0 行)
直接执行:select * from tbbom2 where prodno= 'QKS18 ' and fno+cno+cast(lvl as varchar(50)) not in
(select fno+cno+cast(lvl as varchar(50)) from tmp_bom2) and lvl=1
返回一行数据!不得其解还请前辈们帮忙!
------解决方案--------------------把你的
delete from tbbom2 where prodno=@prodno and fno+cno+cast(lvl as varchar(50)) not in
(select fno+cno+cast(lvl as varchar(50)) from tmp_bom2) and lvl=@tmplvl
写到字符串变量里 然后打印出来
看看跟你写的有什么不同