select 流水号, 货物, 规格, 计量单位, 批号,货物失效日期,数量,
所属单位=(select 所属单位 from a where a.序号 = b.序号) ,
所属供应商=(select 所属供应商 from a where a.序号 = b.序号)
into #t
from b
insert into c(流水号, 货物, 规格, 计量单位, 批号,货物失效日期,数量,所属单位,所属供应商)
select 流水号, 货物, 规格, 计量单位, 批号,货物失效日期,数量,所属单位,所属供应商
from #t as t1,c as t2
where t1.流水号!=t2.流水号 or t1.货物!=t2.货物 or....update c
set 数量=数量+select isnull( (select sum(数量) from #t where
where t1.流水号=t2.流水号 and t1.货物=t2.货物... ))
所属单位=(select 所属单位 from a where a.序号 = b.序号) ,
所属供应商=(select 所属供应商 from a where a.序号 = b.序号)
into #t
from b
insert into c(流水号, 货物, 规格, 计量单位, 批号,货物失效日期,数量,所属单位,所属供应商)
select 流水号, 货物, 规格, 计量单位, 批号,货物失效日期,数量,所属单位,所属供应商
from #t as t1,c as t2
where t1.流水号!=t2.流水号 or t1.货物!=t2.货物 or....update c
set 数量=数量+select isnull( (select sum(数量) from #t where
where t1.流水号=t2.流水号 and t1.货物=t2.货物... ))
解决方案 »
- SQL server 2000 这个JOB怎么写
- 求助:!sqlserver查询问题!
- select top 10 name from a order by sendtime ,用oracle数据库写个存储过程怎么写。
- 把Sql Server7数据恢复到Sql Server2000中,出现完全一样的行记录,如何删除??
- 请教用企业管理器远程控制sql 2000中的数据库为什么不能使用全文索引功能?
- sql 数据挖掘问题
- 有关ADO或ADOX编程
- 补偿过失,zjcxc(邹建) 请接分!!
- c#实现SQL存储pdf文档,搜索
- sql程序设计小白问题
- 求教:如何连接Sql Server2000 服务器?HELP……
- sql错误,求简单变通的方法
create proc p_process
@序号 int
as
set xact_abort on
begin tran
--先更新已经存在的
update c set 数量=b.数量
from a,b,c
where a.序号=@序号 and b.序号=@序号 and a.序号=b.序号
and a.所属单位=c.所属单位 and a.所属供应商=c.所属供应商
and b.货物=c.货物 and b.批号=c.批号 --插入不存在的
insert c(所属单位,所属供应商,货物,规格,计量单位,批号,货物失效日期,数量)
select a.所属单位,a.所属供应商,b.货物,b.规格,b.计量单位,b.批号,b.货物失效日期,b.数量
from a,b,c
where a.序号=@序号 and b.序号=@序号 and a.序号=b.序号
and not exists(
select * from c
where a.所属单位=c.所属单位 and a.所属供应商=c.所属供应商
and b.货物=c.货物 and b.批号=c.批号)
所属供应商=(select 所属供应商 from a where a.序号 = b.序号),货物, 规格, 计量单位, 批号,货物失效日期,数量
into #table
from b ---------使用中间表过渡
insert into c(流水号, 所属单位,所属供应商,货物, 规格, 计量单位, 批号,货物失效日期,数量)
select 流水号, 所属单位,所属供应商,货物, 规格, 计量单位, 批号,货物失效日期,数量
from #table as t1,c as t2
where t1.所属供应商<>t2.所属供应商 and t1.货物<>t2.货物 and t1.计量单位<>t2.计量单位 and t1.批号<>t2.批号
update c
set 数量=数量+(select isnull(sum(数量),0) from #table a where t1.所属供应商=t2.所属供应商 and t1.货物=t2.货物 and t1.计量单位=t2.计量单位 and t1.批号=t2.批号)
一会儿揭贴