免用游标求解SQL过程(200分)

  • 主题发起人 主题发起人 19761211
  • 开始时间 开始时间
1

19761211

Unregistered / Unconfirmed
GUEST, unregistred user!
一、表结构<br>表A(零件库)<br>零件编号  库存量<br>A7788250 &nbsp; 12<br>B7788250 10<br>C7788250 15<br><br>表B:(库存调整)<br>ID 调整单号 零件编号 调整数量<br><br><br>表C:(零件变动)<br>ID &nbsp; DH &nbsp; 零件编号 &nbsp; &nbsp;数量 &nbsp; &nbsp;日期 &nbsp; &nbsp; &nbsp;种类<br><br>二、要进行的操作<br>新开一张库存调整单,数据如下<br>ID &nbsp; &nbsp; &nbsp;调整单号 &nbsp; &nbsp; &nbsp; &nbsp; 零件编号 &nbsp; &nbsp; &nbsp;调整数量<br>1 &nbsp; &nbsp; &nbsp; DT081120001 &nbsp; &nbsp; &nbsp;A7788250 &nbsp; &nbsp; &nbsp;2<br>2 &nbsp; &nbsp; &nbsp; DT081120001 &nbsp; &nbsp; &nbsp;C7788250 &nbsp; &nbsp; &nbsp;-6<br><br>要求根据库存调整单[DT081120001]中的内容,对零件库进行更新,并将本次调整内容写入[零件变动]表<br><br>三、操作后结果如下:<br>表A(零件库)<br>--------------------------------------------------<br>零件编号 &nbsp; &nbsp; &nbsp; 库存量<br>A7788250 &nbsp; &nbsp; &nbsp; 14<br>B7788250 &nbsp; &nbsp; &nbsp; 10<br>C7788250 &nbsp; &nbsp; &nbsp; 9<br><br>表C:(零件变动)<br>-----------------------------------------------------------------------------------<br>ID &nbsp; &nbsp; &nbsp;DH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 零件编号 &nbsp; 数量 &nbsp; &nbsp; 日期 &nbsp; &nbsp; &nbsp; 种类<br>1 &nbsp; &nbsp; &nbsp; DT081120001 &nbsp;A7788250 &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp;getdate() &nbsp;调库<br>2 &nbsp; &nbsp; &nbsp; DT081120001 &nbsp;C7788250 &nbsp; -6 &nbsp; &nbsp; &nbsp; getdate() &nbsp;调库<br><br><br>四、要求:不能使用游标
 
update 本来就可以 连接 2表啊
 
/*<br>表A(零件库)<br>零件编号  &nbsp; &nbsp;库存量<br>A7788250 &nbsp; &nbsp; &nbsp;12<br>B7788250 &nbsp; &nbsp;10<br>C7788250 &nbsp; &nbsp;15<br>*/<br>create table [零件库] ( [零件编号] varchar(20),[库存量] int) <br>insert into [零件库] values('A7788250 ',12)<br>insert into [零件库] values('B7788250',10)<br>insert into [零件库] values('C7788250',15)<br><br>/*<br>新开一张库存调整单,数据如下<br>ID &nbsp; &nbsp; &nbsp;调整单号 &nbsp; &nbsp; &nbsp; &nbsp; 零件编号 &nbsp; &nbsp; &nbsp;调整数量<br>1 &nbsp; &nbsp; &nbsp; DT081120001 &nbsp; &nbsp; &nbsp;A7788250 &nbsp; &nbsp; &nbsp;2<br>2 &nbsp; &nbsp; &nbsp; DT081120001 &nbsp; &nbsp; &nbsp;C7788250 &nbsp; &nbsp; &nbsp;-6<br>*/<br>create table [调整单] ( [ID] int,[调整单号] varchar(20),[零件编号] varchar(20),[调整数量] int) <br>insert into [调整单] values(1,'DT081120001','A7788250 ',2)<br>insert into [调整单] values(2,'DT081120001','C7788250',-6)<br><br>update [零件库] set [库存量]=[库存量]+[调整数量] from [零件库],[调整单] where [零件库].[零件编号]=[调整单].[零件编号]<br><br>select * from &nbsp;[零件库] <br><br><br>drop table [零件库]<br>drop table [调整单]
 
insert into 零件变动<br>我就不写了
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
D
回复
0
查看
837
DelphiTeacher的专栏
D
后退
顶部