标签:where
--------------------
--查询收款明细
select L.SKTNO,L.JLBH,C.DEPTID,L.JZRQ,L.JYSJ
into #SKTJL
from BFBHDD.SKTXSJL L,BFBHDD.SKTXSJLC C
where L.SKTNO=C.SKTNO
and L.JLBH=C.JLBH
and L.JZRQ>=‘2014-8-1‘
and L.JZRQ<=‘2014-8-31‘
group by L.SKTNO,L.JLBH,C.DEPTID,L.JZRQ,L.JYSJ
select * from #SKTJL
--drop table #SKTJL
--获取消费明细
insert into BFBHDD.CZKXFJL
select L.DEPTID,D.HTH,X.KKBL,L.SKTNO,L.JLBH,L.JZRQ,L.JYSJ,sum(M.SKJE) SKJE,sum(M.SKJE)*X.KKBL KKJE
from BFBHDD.SKTXSJLM M,#SKTJL L,BFBHDD.HT_KKXM X,BFBHDD.HT_DHBM D
where L.SKTNO=M.SKTNO
and L.JLBH=M.JLBH
and L.DEPTID=D.DEPTID
and D.HTH=X.HTH
and M.SKFS in (15,3,16,18)
and X.KKXMID=15
and D.HTH<90000000
group by L.DEPTID,D.HTH,X.KKBL,L.SKTNO,L.JLBH,L.JZRQ,L.JYSJ
select * from #SKBL
--获取扣款比率等数据
insert into BFBHDD.KKBL
select L.DEPTID,D.HTH,201408,X.KKBL,I.YKKJE,sum(M.SKJE) SKJE,sum(M.SKJE)*X.KKBL KKJE
from BFBHDD.SKTXSJLM M,#SKTJL L,BFBHDD.HT_KKXM X,BFBHDD.HT_DHBM D,BFBHDD.JSDKKITEM I
where L.SKTNO=M.SKTNO
and L.JLBH=M.JLBH
and L.DEPTID=D.DEPTID
and D.HTH=X.HTH
and M.SKFS in (15,3,16,18)
and X.KKXMID=15
and D.HTH<90000000
and I.DEPTID=L.DEPTID
and I.JSKKID=15
group by L.DEPTID,D.HTH,X.KKBL,I.YKKJE
---------------------------
drop table BFBHDD.CZKXFJL
GO
create table BFBHDD.CZKXFJL(
JLBH int identity,
DEPTID varchar(10) not null,
HTH int not null,
KKBL float not null,
SKTNO varchar(3) not null,
SKTJLBH int not null,
JZRQ datetime not null,
JYSJ datetime not null,
SKJE money not null,
KKJE money not null,
constraint PK_CZKXFJL PRIMARY KEY CLUSTERED (JLBH)
)
with identity_gap=1
GO
drop table BFBHDD.KKBL
GO
create table BFBHDD.KKBL(
JLBH INT identity,
DEPTID varchar(10) not null,
HTH int not null,
YEARMONTH int not null,
KKBL float not null,
YKKJE money null,
SKJE money not null,
KKJE money not null,
constraint PK_KKBL PRIMARY KEY CLUSTERED (JLBH)
)with identity_gap=1
GO
-------------------------
标签:where
原文地址:http://lj1987.blog.51cto.com/167978/1548268