/****** Object: StoredProcedure [dbo].[sSysGetBillNo] Script Date: 01/05/2014 20:45:13 ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sMsGetML]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[sSysGetBillNo] GO /****** Object: StoredProcedure [dbo].[sSysGetBillNo] Script Date: 01/05/2014 20:45:13 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO Create PROCEDURE [dbo].[sMsGetML] ( @contractno varchar(50)='' ) --WITH ENCRYPTION AS Begin select max(RMBYS) RMBYS,max(RMBYF) RMBYF,max(RMBYS)-max(RMBYF) RMBML, max(USDYS) USDYS,max(USDYF) USDYF,max(USDYS) -max(USDYF) USDML from(select sum(amount) RMBYS,0 RMBYF,0 USDYS,0 USDYF from ch_fee where feetype=1 and bsno=@contractno and currency='RMB' union all select 0,sum(amount) ,0,0 from ch_fee where feetype=2 and bsno=@contractno and currency='RMB' union all select 0,0,sum(amount) ,0 from ch_fee where feetype=1 and bsno=@contractno and currency='USD' union all select 0,0,0,sum(amount) from ch_fee where feetype=2 and bsno=@contractno and currency='USD' )t1 End GO