我创建了一个可以工作并提供我想要的查询,但是它不会在批处理文件中执行。如何使用成功执行的查询的结果填充另一个表?
这是我的查询
select
isnull (start_charge.account,'No account at start') Start_charge_account
,Finish_charge.account start_charge_account
,case when start_charge.account is null then finish_charge.account else start_charge.account end "account"
,isnull (start_charge.Branch,99999999999) Start_charge_Branch
,Finish_charge.Branch Finish_charge_Branch
,case when start_charge.branch is null then finish_charge.branch else start_charge.branch end " branch"
,isnull (start_charge. site_number,99999999999) Start_charge_site_number
,Finish_charge. site_number Finish_charge_site_number
,case when start_charge.site_number is null then finish_charge.site_number else start_charge.site_number end "site_number"
,isnull (start_charge. service_code, 'No account at start') Start_charge_service_code
,Finish_charge. service_code finish_charge_service_code
,isnull (start_charge. item_code,'No account at start') Start_charge_item_code
,Finish_charge. item_code finish_charge_item_code
,isnull (start_charge. why_code, 'No account at start') Start_charge_why_code
,Finish_charge. why_code finish_charge_why_code
,isnull (start_charge. why_type, 'No account at start') Start_charge_why_type
,Finish_charge. why_type finish_charge_why_type
,Start_charge.Start_charge
,isnull(Finish_charge.Finish_charge,0) Finish_charge
,isnull(Start_charge.Start_charge,0)-isnull(Finish_charge.Finish_charge,0) Variance
from
(
select
account
,branch
,site_number
,service_code
,item_code
,why_code
,why_type
,sum(charge)
"Start_Charge"
from
cannon_commercial
where
1=1
and record_type = 'PS'
and period = ' 02/07/2013'
group by
account
,branch
,site_number
,service_code
,item_code
,why_code
,why_type
) start_charge
full outer join
( select
account
,branch
,site_number
,service_code
,item_code
,why_code
,why_type
,concat(account,site_number) "account - site"
,ISNULL(sum(charge),0) "Finish_Charge"
from
cannon_commercial
where
1=1
and record_type= 'PS'
and period = ' 04/06/2013'
group by
account
,branch
,site_number
,service_code
,item_code
,why_code
,why_type
)
Finish_charge
on Start_charge.Account = Finish_charge.Account
and Start_charge.Branch = Finish_charge.Branch
and Start_charge.site_number = Finish_charge.site_number
and Start_charge.item_code = Finish_charge.item_code
and Start_charge.service_code = Finish_charge.service_code
and Start_charge.why_code = Finish_charge.why_code
and Start_charge.why_type = Finish_charge.why_type