You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/word/新协航_设计文档/数据库建表文档/1.0/报表_客户对账.sql

46 lines
3.8 KiB
Transact-SQL

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

--update ch_fee set amount=unitprice*quantity
--select * from ch_fee
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vImprotRPT_KHDZ]'))
DROP VIEW [dbo].[vImprotRPT_KHDZ]
GO
/****** Object: View [dbo].[vImprotRPT_KHDZ] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[vImprotRPT_KHDZ]
AS
select bsno,sum() ,sum() ,sum() ,sum()
,sum() ,sum(THC) THC,sum() ,sum()
,sum() ,sum() ,sum() ,sum()
,sum()+sum()+sum()+sum()+sum()+sum(THC)+sum()+sum()+
sum()+sum()+sum()+sum()
from(
select bsno,
case feename when '预付款' then convert(numeric(18,2), amount*exchangerate) else 0 end [预付款],
case feename when '尾款' then convert(numeric(18,2), amount*exchangerate) else 0 end [尾款],
case feename when '增值税' then convert(numeric(18,2), amount*exchangerate) else 0 end [增值税],
case feename when '关税' then convert(numeric(18,2),amount*exchangerate) else 0 end [关税],
case feename when '代理费' then convert(numeric(18,2),amount*exchangerate) else 0 end [代理费],
case feename when 'THC' then convert(numeric(18,2),amount*exchangerate) else 0 end [THC],
case feename when '拖车费' then convert(numeric(18,2),amount*exchangerate) else 0 end [拖车费],
case feename when '验货费' then convert(numeric(18,2),amount*exchangerate) else 0 end [验货费],
case feename when '滞期费' then convert(numeric(18,2),amount*exchangerate) else 0 end [滞期费],
case feename when '超期制冷费' then convert(numeric(18,2),amount*exchangerate) else 0 end [超期制冷费],
case feename when '冷藏费' then convert(numeric(18,2),amount*exchangerate) else 0 end [冷藏费],
case feename when '出入库费' then convert(numeric(18,2),amount*exchangerate) else 0 end [出入库费]
from ch_fee where feetype=1
) tt
group by tt.bsno
--where bsno='A1'
select * from [vImprotRPT_KHDZ]
where bsno in(select contractno from import_main m where (1=1) )