日期:2014-05-17  浏览次数:20333 次

求高手一个存储过程,谢啦
是这样的,我有 3 张表  A,B,C
 其中 A的结构式这样的
money,consig,costname,remark

B的结构式这样的
ID,consig

C的结构式这样的
ID,shouldmoney,date,isClose

b与c式主外键关系

我想做的事 根据条件(date为时间类型,isClose=‘1’) 查出 B,C量表的consig和shouldmoney 付给A表的consig和money(查到多少付多少),其中costname和remark是从页面传来的也要附给A表
求高手 解答,谢啦,在线等

------解决方案--------------------
declare @date date,@costname varchar(20),@remark varchar(max)

with cte
as
(
select SUM(consig) consig,SUM(shouldmoney) shouldmoney
from
B inner join C on B.ID=C.ID
where C.date=@date and C.isClose='1'
)
select consig,shouldmoney,@costname,@remark
into A
from cte