日期:2014-05-18  浏览次数:20659 次

问下存储过程里的这段代码啥意思
update   资产负债表   set   现金及现金等价物   =   b.金额   from   资产负债表   as   a,
(select   sum(isnull(本期借方余额,0)-isnull(本期贷方余额,0))   as   金额
from   科目余额表   where   会计期间   =   @kjqj   and  
科目代码   > =   101   and   科目代码   <=   111)
as   b   where   a.会计期间   =   @kjqj

------解决方案--------------------
update a
set 现金及现金等价物 = b.金额
from 资产负债表 as a,
( select sum(isnull(本期借方余额,0)-isnull(本期贷方余额,0)) as 金额
from 科目余额表
where 会计期间 = @kjqj and 科目代码 between 101 and 111) as b
where a.会计期间 = @kjqj
------解决方案--------------------
拆分:
1.update 资产负债表 set 现金及现金等价物 = b.金额 from 资产负债表 as a,[$select..$] as b where a.会计期间 = @kjqj

2.[$select..$]::=
(select sum(isnull(本期借方余额,0)-isnull(本期贷方余额,0)) as 金额
from 科目余额表 where 会计期间 = @kjqj and
科目代码 > = 101 and 科目代码 <= 111)