--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) )