以前用过的,但今天不知道发什么神经就忘了,还搜了半天没搜到,记一下备忘 begin declare @cbjbh int declare @sumZtz decimal declare @kssj datetime declare @jssj datetime declare @bmdm varchar(6) set @kssj='1900-1-1' set @jssj='2099-1-1' set @bmdm='' select xh into temp1 from tab_zbb_gkzb where kssj>@kssj and kssj<@jssj and bjbh in (select bjbh from tab_zbb_xmbjxx where bmdm like '%'+@bmdm+'%') select @cbjbh=count(bjbh),@sumZtz=sum(ztz) from tab_zbb_xmbjxx where bmdm like '%'+@bmdm+'%' and bjbh in (select bjbh from tab_zbb_gkzb where kssj>@kssj and kssj<@jssj) select @cbjbh as xmsl,@sumZtz as ztz ,(select count(xh) from tab_zbb_paylog where (PayType='2' or PayType='3') and xh in (select xh from temp1)) as sqjs ,(select count(xh) from tab_zbb_paylog where (PayType='2' or PayType='3') and SignSequenceNo is not NULL and xh in (select xh from temp1)) as qdjs ,(select sum(PayUsNumber) from tab_zbb_paylog where PayType!='2' and PayState!='0' and xh in (select xh from temp1)) as fy1 ,(select sum(PayUsNumber) from tab_zbb_paylog where PayType='2')+(select sum(PayPbf) from tab_zbb_paylog where PayType='3' and PayState='1' and xh in (select xh from temp1)) as fy2 drop table temp1 end