查询分析工具提示在对应所需名称或序数的集合中,未找到...
金蝶云社区-云社区用户7n6j8579
云社区用户7n6j8579
0人赞赏了该文章 688次浏览 未经作者许可,禁止转载编辑于2016年12月08日 10:34:07

您好,查询分析工具提示【在对应所需名称或序数的集合中,,未找到项目】以下是我的sql,麻烦看看有什么问题
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[ntk_库存账龄分析表最新]
@itemnumber varchar(50),
@stocknumber varchar(20),
@fdate datetime
as

set nocount on;

select * into #test1 from ICInventory
update #test1 set fkfdate = @fdate where #test1.fkfdate = ''

select IDENTITY(INT,1,1) AS '序号',
case when grouping(t_ICItem.fnumber)=1 and grouping(convert(varchar(10),#test1.fkfdate,120))=0 then '小计'
else t_ICItem.fnumber end as '物料长代码'
,convert(varchar(10),#test1.fkfdate,120) 生产时间
,#test1.fitemid 内码
,t_ICItem.fname 物料名称
,t_ICItem.fmodel 规格型号
,t_Stock.fnumber 仓库ID
,t_Stock.fname 仓库名称
,t_MeasureUnit.FName 计量单位
,sum(case when (datediff(day,#test1.fkfdate,@fdate) <=30) then #test1.fqty end)as '30天以内'
,sum(case when (datediff(day,#test1.fkfdate,@fdate) >30)and (datediff(day,#test1.fkfdate,@fdate) <=60)
then #test1.fqty end ) as '30-60天'
,sum(case when (datediff(day,#test1.fkfdate,@fdate) >60)and (datediff(day,#test1.fkfdate,@fdate) <=90)
then #test1.fqty end )as '60-90天'
,sum(case when (datediff(day,#test1.fkfdate,@fdate) >90)and (datediff(day,#test1.fkfdate,@fdate) <=180)
then #test1.fqty end )as '90-180天'
,sum(case when (datediff(day,#test1.fkfdate,@fdate) >180)and (datediff(day,#test1.fkfdate,@fdate) <=360)
then #test1.fqty end )as '180-360天'
,sum(case when (datediff(day,#test1.fkfdate,@fdate) >360) then #test1.fqty end )as '360天以上'
,sum(#test1.fqty) 小计
into #test
from #test1
inner join t_ICItem on t_ICItem.fitemid= #test1.fitemid
left join t_Stock on #test1.fstockid = t_Stock.FItemID
left join t_MeasureUnit on t_MeasureUnit.FItemID = t_ICItem.FUnitID
where isnull(#test1.fqty,0)<>0
and t_ICItem.fnumber like '%'+ @itemnumber +'%'
and t_Stock.fnumber like '%'+ @stocknumber +'%'
group by #test1.fitemid
,convert(varchar(10),#test1.fkfdate,120)
,t_ICItem.FNumber
,t_ICItem.fname
,t_ICItem.fmodel
,#test1.fkfdate
,t_Stock.fnumber
,t_Stock.fname
,t_MeasureUnit.FName
with rollup
having
(grouping(t_ICItem.fnumber)=0
and grouping(convert(varchar(10),#test1.fkfdate,120))=0
and grouping(#test1.FItemID)=0
and grouping(t_ICItem.fname)=0
and grouping(t_Stock.fnumber)=0
and grouping(t_Stock.fname)=0
and grouping(t_MeasureUnit.FName)=0
and grouping(#test1.fkfdate)=0
)
or (grouping(t_ICItem.fnumber)=1 and grouping(convert(varchar(10),#test1.fkfdate,120))=0)
order by #test1.fitemid ,t_Stock.fnumber

set nocount off;

select [物料长代码],[物料名称],[规格型号],[仓库ID],[仓库名称],[计量单位]
,isnull(sum([30天以内]),0) as '30天以内'
,isnull(sum([30-60天]),0) as '30-60天'
,isnull(sum([60-90天]),0) as '60-90天'
,isnull(sum([90-180天]),0) as '90-180天'
,isnull(sum([180-360天]),0) as '180-360天'
,isnull(sum([360天以上]),0) as '360天以上'
,sum([小计]) as '小计'
from #test
group by [物料长代码],[物料名称],[规格型号],[仓库ID],[仓库名称],[计量单位]

drop table #test
drop table #test1