文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

数码产品各店面分析

2024-04-02 19:55

关注

//数码产品各店面分析报表//


BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;
create table #temp12([日期] datetime,[部门代码] varchar(100),[部门名称]  varchar(100), [商品代码]  varchar(100),
[商品名称]  varchar(100),[品牌] varchar(100),[数量] int,[含税金额] decimal(10,2),
[不含税金额] decimal(10,2),[成本] decimal(10,2))

insert into #temp12
select t0.F_PBKA_DATE,
t12.fnumber,t11.fname fname1,t2.FNUMBER,t3.FNAME,t2.F_PBKA_MOBILE_BRANK,
case when t0.FBILLTYPEID='57faf492b10d31' then sum(isnull(t1.FQTY,0))
 when  t0.FBILLTYPEID='580778655b6d7d' then  -sum(isnull(t1.FQTY,0))  end FQTY,
case when t0.FBILLTYPEID='57faf492b10d31' then sum(isnull(t1.FSDJAMOUNT ,0))
 when  t0.FBILLTYPEID='580778655b6d7d' then  -sum(isnull(t1.FSDJAMOUNT ,0))  end 含税金额,
 case when t0.FBILLTYPEID='57faf492b10d31' then sum(isnull(t1.F_PBKA_BHSAMOUNT ,0))
 when  t0.FBILLTYPEID='580778655b6d7d' then  -sum(isnull(t1.F_PBKA_BHSAMOUNT ,0))  end 不含税金额,0
from PBKA_t_BillHead t0
inner join PBKA_t_GoodsDetail t1 on t0.fid=t1.fid
left join t_bd_material t2 on t1.FMATERIALID=t2.FMATERIALID
inner join T_BD_MATERIAL_L t3 on t1.FMATERIALID=t3.FMATERIALID and t3.FLOCALEID=2052
inner join t_bd_material t9 on t3.FMATERIALID=t9.FMATERIALID
join t_bd_department_l t11 on t0.FOLDDEPARTMENT=t11.FDEPTID
join t_bd_department t12 on t11.FDEPTID=t12.FDEPTID
where  t12.fnumber like '203%'and t9.FNUMBER like '03%'
and (convert(varchar(10),t0.F_PBKA_DATE,21)>='2017-03-01'
and convert(varchar(10),t0.F_PBKA_DATE,21)<='2017-03-31')
 
group by  t0.F_PBKA_DATE,t2.FNUMBER,t11.fname,t12.fnumber,t3.FNAME,t2.F_PBKA_MOBILE_BRANK,t0.FBILLTYPEID order by 1


insert into #temp12
select t0.FDATE,t12.FNUMBER FNUMBER,t11.fname fname1, t9.FNUMBER,t5.FNAME,t9.F_PBKA_MOBILE_BRANK,0,0,0,sum(t2.FCOSTAMOUNT)
 From T_SAL_OUTSTOCK t0
      join  T_SAL_OUTSTOCKENTRY t1 on t0.FID =t1.fid
      join T_SAL_OUTSTOCKENTRY_F t2 on t1.FENTRYID =t2.FENTRYID
      join t_bd_material_l t5 on t1.FMATERIALID =t5.FMATERIALID and FLOCALEID=2052
      join t_bd_material t9 on t5.FMATERIALID=t9.FMATERIALID
     join  T_SAL_OUTSTOCKENTRY_R t10 on t2.FENTRYID=t10.FENTRYID
     join t_bd_department_l t11 on t0.FOLDDEPARTMENT=t11.FDEPTID
                join t_bd_department t12 on t11.FDEPTID=t12.FDEPTID
      where  (convert(varchar(10),t0.fdate,21)>='2017-03-01'
          and convert(varchar(10),t0.fdate,21)<='2017-03-31') 
       and t10.FSRCTYPE ='PBKA_XSKD'  and t9.fnumber like '03%'   and t12.fnumber like '203%'
         group by t0.FDATE,t12.FNUMBER,t11.fname, t9.FNUMBER,t5.FNAME,t9.F_PBKA_MOBILE_BRANK

insert into #temp12
select t0.fdate,t12.FNUMBER FNUMBER,t11.fname fname1, t9.FNUMBER,t5.FNAME,t9.F_PBKA_MOBILE_BRANK,0,0,0,-sum(t2.FCOSTAMOUNT)
 From T_SAL_RETURNSTOCK t0
      join  T_SAL_RETURNSTOCKENTRY t1 on t0.FID =t1.fid
      join T_SAL_RETURNSTOCKENTRY_F t2 on t1.FENTRYID =t2.FENTRYID
      join t_bd_material_l t5 on t1.FMATERIALID =t5.FMATERIALID and FLOCALEID=2052
      join t_bd_material t9 on t5.FMATERIALID=t9.FMATERIALID
     join  T_SAL_RETURNSTOCKENTRY_R t10 on t2.FENTRYID=t10.FENTRYID
     join t_bd_department_l t11 on t0.FOLDDEPARTMENT=t11.FDEPTID
                join t_bd_department t12 on t11.FDEPTID=t12.FDEPTID
      where  (convert(varchar(10),t0.fdate,21)>='2017-03-01'
          and convert(varchar(10),t0.fdate,21)<='2017-03-31')
       and t10.FSRCBILLTYPEID ='PBKA_XSKD'   and t12.fnumber like '203%' and t9.fnumber like '03%'
       group by t0.fdate,t12.FNUMBER,t11.fname, t9.FNUMBER,t5.FNAME,t9.F_PBKA_MOBILE_BRANK
 declare @Sql varchar(8000)
 select @sql=''
 declare @sql1  varchar(8000)
 select @sql1=''
 create table #table21 ([商品名称]  varchar(100),[部门名称] varchar(100),[数量] int,[含税金额] decimal(18,2),[毛利] decimal(18,2))
 create table #table22 ([商品名称]  varchar(100),[部门名称] varchar(100),[数量]int,[含税金额] decimal(18,2),[毛利] decimal(18,2))
   insert into #table21
select  [商品名称] ,[部门名称],sum([数量]),sum([含税金额]) [含税金额],sum([不含税金额])-sum([成本])  from #temp12
group by  [商品名称] ,[部门名称]
insert into #table22
select [商品名称],[部门名称],sum([数量]),sum([含税金额]),sum([毛利]) from #table21 group by [商品名称],[部门名称]

  create table #table1 ([商品名称] varchar(100),[部门名称] varchar(100),[数量] int,[含税金额] decimal(18,2),[毛利] decimal(18,2))

    set @sql1='insert into #table1 '
  set @sql1= @sql1+ ' select [商品名称],[部门名称],[数量],[含税金额],[毛利] from  #table22 '
 exec (@Sql1)
  set @sql1='insert into #table1 '
  set @sql1= @sql1+ '  select ''小计'',[部门名称],sum([数量]),sum([含税金额]),sum([毛利])  from  #table22 '
  set @sql1= @sql1+ ' GROUP BY [部门名称] '
-- exec (@Sql1)
--set @sql1='insert into #table1 '
--  set @sql1= @sql1+ '  select ''总计'',[部门名称],sum([含税金额]),sum([毛利]) from  #table22 '
--  set @sql1= @sql1+ '   GROUP BY [部门名称] '
 exec (@Sql1)

    set @sql='select [商品名称] 商品名称,'
    select @sql= @sql+'sum(case [部门名称] when '''+[部门名称]+'''
     then         数量 else 0 end) as ['+[部门名称]+'|数量],
  sum(case [部门名称] when '''+[部门名称]+'''
     then         含税金额 else 0 end) as ['+[部门名称]+'|含税金额],
  sum(case [部门名称] when '''+[部门名称]+'''
     then         毛利 else 0 end) as ['+[部门名称]+'|毛利],'
  from (select distinct [部门名称] from #table1) as a
  select @sql=left(@sql,len(@sql)-1)+' ,sum(数量) [合计数量],sum(含税金额) [合计含税金额],sum(毛利) [合计毛利]'+'from #table1 group by [商品名称] '
 
      exec (@sql)
 
drop table #table21,#table22,#temp12,#table1
END

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯