|
drop table #sxy1
drop table #sxy2
drop table #sxy3
drop table #sxy4
drop table #sxy5
drop table #sxy6
drop table #sxy7
select branch,aracde,sum(acctamt_std1+acctamt_std2)/10000 bf into #sxy1 from ipe_cbtg_all where trandate between 20100101 and 20100331 and branch='B0' group by branch,aracde
select branch,aracde,agntnum,sum(acctamt_std1+acctamt_std2) grbf into #sxy2 from ipe_cbtg_all where trandate between 20100101 and 20100131 group by branch,aracde,agntnum having sum(acctamt_std1+acctamt_std2)>=1000 and branch='B0'
select branch,aracde,agntnum,sum(acctamt_std1+acctamt_std2) grbf into #sxy3 from ipe_cbtg_all where trandate between 20100201 and 20100231 group by branch,aracde,agntnum having sum(acctamt_std1+acctamt_std2)>=1000 and branch='B0'
select branch,aracde,agntnum,sum(acctamt_std1+acctamt_std2) grbf into #sxy4 from ipe_cbtg_all where trandate between 20100301 and 20100331 group by branch,aracde,agntnum having sum(acctamt_std1+acctamt_std2)>=1000 and branch='B0'
select branch,aracde,count(agntnum) rs1 into #sxy5 from #sxy2 group by branch,aracde
select branch,aracde,count(agntnum) rs2 into #sxy6 from #sxy3 group by branch,aracde
select branch,aracde,count(agntnum) rs3 into #sxy7 from #sxy4 group by branch,aracde
select a.branch,a.aracde,a.bf,b.rs1,c.rs2,d.rs3 from #sxy1 a
left outer join #sxy5 b on a.aracde=b.aracde
left outer join #sxy6 c on a.aracde=c.aracde
left outer join #sxy7 d on a.aracde=d.aracde
group by a.branch,a.aracde,a.bf,b.rs1,c.rs2,d.rs3
order by a.branch,a.aracde
drop table #sxy1
drop table #sxy2
drop table #sxy3
drop table #sxy4
drop table #sxy5
drop table #sxy6
drop table #sxy7
select branch,partnum,sum(acctamt_std1+acctamt_std2)/10000 bf into #sxy1 from ipe_cbtg_all where trandate between 20100101 and 20100331 and branch='B0' group by branch,partnum
select branch,partnum,agntnum,sum(acctamt_std1+acctamt_std2) grbf into #sxy2 from ipe_cbtg_all where trandate between 20100101 and 20100131 group by branch,partnum,agntnum having sum(acctamt_std1+acctamt_std2)>=1000 and branch='B0'
select branch,partnum,agntnum,sum(acctamt_std1+acctamt_std2) grbf into #sxy3 from ipe_cbtg_all where trandate between 20100201 and 20100231 group by branch,partnum,agntnum having sum(acctamt_std1+acctamt_std2)>=1000 and branch='B0'
select branch,partnum,agntnum,sum(acctamt_std1+acctamt_std2) grbf into #sxy4 from ipe_cbtg_all where trandate between 20100301 and 20100331 group by branch,partnum,agntnum having sum(acctamt_std1+acctamt_std2)>=1000 and branch='B0'
select branch,partnum,count(agntnum) rs1 into #sxy5 from #sxy2 group by branch,partnum
select branch,partnum,count(agntnum) rs2 into #sxy6 from #sxy3 group by branch,partnum
select branch,partnum,count(agntnum) rs3 into #sxy7 from #sxy4 group by branch,partnum
select a.branch,a.partnum,a.bf,b.rs1,c.rs2,d.rs3 from #sxy1 a
left outer join #sxy5 b on a.partnum=b.partnum
left outer join #sxy6 c on a.partnum=c.partnum
left outer join #sxy7 d on a.partnum=d.partnum
group by a.branch,a.partnum,a.bf,b.rs1,c.rs2,d.rs3
order by a.branch,a.partnum
只是将上面一段代码(红色)中的ARACDE替换成PARTNUM,变成第二段代码(紫色)。第二段代码运行错误如下:
服务器: 消息 207,级别 16,状态 3,行 13
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 13
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 14
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 14
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 15
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 15
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
服务器: 消息 207,级别 16,状态 1,行 16
Invalid column name 'partnum'.
谁帮忙指点下,晕啊 |
|