|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
以下是我写的一个存储过程,比较粗糙。但是,我现在想实现 @cInvCode 这个参数能在uap报表的过滤条件中实现多项选择,就是一次可以选择多个存货档案进行报表查询,不知要如何写,请高人指教,小弟在此先拜谢了!!!
alter procedure tabAccountNew
@Sdate varchar(10)='',
@Edate varchar(10)='',
@cInvCode varchar(50)='',
@cwhcode varchar(100)='',
@cfree varchar(100)=''
as
declare @sql nvarchar(4000),@filterStr varchar(100),@cwh varchar(100),@cf varchar(100)
if @cInvCode <> ''
set @filterStr = 'a.cInvCode like ''%' + @cInvCode + '%'''
else set @filterStr='1 = 1'
if @Sdate = ''
set @Sdate= '1 = 1'
if @Edate= ''
set @Edate= '1 = 1'
if @cwhcode <> ''
set @cwh = 'b.cwhcode like ''%' + @cwhcode + '%'''
else set @cwhcode ='1 = 1'
if @cfree <>''
set @cf = 'a.cFree1 like ''%' + @cfree + '%'''
else set @cf = '1 = 1'
SET @sql = '
delete from dbo.a
INSERT INTO dbo.a select cInvCName,a.cwhcode,a.cInvCode,cInvName,a.cFree1,sum(在途量)ZTL,sum(成品入库量) RKL,sum(销售出库量) CKL,iQuantity from(
--调拨在途
select cInvCName,a.cwhcode,b.cInvCode,cInvName,cFree1,b.iQuantity as 在途量,0 成品入库量,0 as 销售出库量 from RdRecord a, RdRecords b ,Inventory c ,InventoryClass d where a.id=b.id and a.cbustype= ''调拨入库'' and csource=''调拨''
and isnull(a.chandler,'''')='''' and convert(varchar(10),ddate,120) between ''' + @Sdate + ''' and ''' + @Edate + ''' and c.cInvCode=b.cInvCode and c.cInvCCode = d.cInvCCode
union
--产品入库
select cInvCName,a.cwhcode,b.cInvCode,cInvName,cFree1,0 在途量,b.iQuantity as 成品入库量,0 as 销售出库量 from RdRecord a,RdRecords b, Inventory c ,InventoryClass d where a.id=b.id and a.cbustype=''成品入库''
and isnull(a.chandler,'''')<>'''' and convert(varchar(10),ddate,120) between ''' + @Sdate + ''' and ''' + @Edate + ''' and c.cInvCode=b.cInvCode and c.cInvCCode = d.cInvCCode
union
--销售出库量
select cInvCName,a.cwhcode,b.cInvCode,cInvName,cFree1,0 在途量,0 成品入库量,b.iQuantity as 销售出库量 from RdRecord a,RdRecords b, Inventory c ,InventoryClass d where a.id=b.id and a.cbustype=''普通销售''
and isnull(a.chandler,'''')<>'''' and convert(varchar(10),ddate,120) between ''' + @Sdate + ''' and ''' + @Edate + ''' and c.cInvCode=b.cInvCode and c.cInvCCode = d.cInvCCode
) a ,CurrentStock b where ' + @filterStr +' and ' + @cwh + ' and ' + @cf + ' and b.cInvCode=a.cInvCode and b.cwhcode=a.cwhcode
group by cInvCName,a.cwhCode,a.cInvCode,cInvName,a.cFree1,iQuantity
select * from dbo.a'
EXEC (@sql) |
|