如何修改参数?

以下是甲方旧报表的sql,他们是头部将finereport参数传给它,尾部直接调用数据库的参数,我要在sqlserver弄T+1再用KETTLE抽到MySQL中间库,最终是在帆软上调用这个mysql的中间库,难的是他们要求的时间维度有很多种,我应该怎么去改这个参数好呢?

declare @startTime datetime ,@endTime datetime

 select @startTime='${startTime}' ,@endTime='${endTime}'

--select @startTime = '2021-06-01', @endTime = '2021-06-10'

SELECT f.FarmID,

       f.FarmName as '猪场',

       f.FarmName+line.LineName as '生产线',

       ''         as '计划配种数',

       (select count(*)

        from ([Pigs].[T_Mating] as mating

                 LEFT JOIN V_PigsArchives AS arc

                           ON mating.PigsArchivesID = arc.PigsArchivesID

                 LEFT JOIN Farm.T_Houses AS house

                           ON house.HouseID = arc.HouseID)

        where mating.FirstMatingDate between @startTime and @endTime

          and house.ProductionLineID = line.ProductionLineID

       )          as '实际配种数',

       (select count(*)

        from ([Pigs].[T_PregnancyTest] as pre

                 LEFT JOIN V_PigsArchives AS arc

                           ON pre.PigsArchivesID = arc.PigsArchivesID

                 LEFT JOIN Farm.T_Houses AS house

                           ON house.HouseID = arc.HouseID)

        where pre.PregnancyTestDate between @startTime and @endTime

          and house.ProductionLineID = line.ProductionLineID

          and (pre.PregnancyTestResult = 2 or pre.PregnancyTestResult = 3)

       )          as '返情空怀',

          isnull((select count(*)

        from ([Pigs].[T_PregnancyTest] as pre

                 LEFT JOIN V_PigsArchives AS arc

                           ON pre.PigsArchivesID = arc.PigsArchivesID

                 LEFT JOIN Farm.T_Houses AS house

                           ON house.HouseID = arc.HouseID

                 right join [Pigs].[T_Death] death on arc.PigsArchivesID = death.PigsArchivesID)

        where pre.PregnancyTestDate between @startTime and @endTime

          and house.ProductionLineID = line.ProductionLineID

          and (pre.PregnancyTestResult = 2 or pre.PregnancyTestResult = 3)

          and (death.DeathDate between @startTime and @endTime or arc.EliminatedDate between @startTime and @endTime)),0)

                  as '妊娠期淘汰数',

       (select count(*)

        from ([Pigs].[T_PregnancyTest] as pre

                 LEFT JOIN V_PigsArchives AS arc

                           ON pre.PigsArchivesID = arc.PigsArchivesID

                 LEFT JOIN Farm.T_Houses AS house

                           ON house.HouseID = arc.HouseID)

        where pre.PregnancyTestDate between @startTime and @endTime

          and house.ProductionLineID = line.ProductionLineID

          and (pre.PregnancyTestResult = 4)

       )          as '流产'

(select count(*)

        from ([Pigs].[T_ChangeHouse] as change

                 LEFT JOIN V_PigsArchives AS arc

                           ON change.PigsArchivesID = arc.PigsArchivesID

                 LEFT JOIN Farm.T_Houses AS house

                           ON house.HouseID = arc.HouseID)

        where change.ChangeHouseDate between @startTime and @endTime

          and house.ProductionLineID = line.ProductionLineID

       )          as '场内调动'

FROM [Farm].[T_Farms] f

         right join [Farm].[T_ProductionLine] line

                    on f.FarmID = line.FarmID

where f.OrganID = 1 and f.IsDeleted=0 and f.FarmName!='虚拟公猪站'

${if(len(FarmID) == 0,""," and f.FarmID = '" + FarmID + "'")}

${if(len(ProductionLineID) == 0,""," and line.ProductionLineID = '" + ProductionLineID + "'")}

group by f.FarmID,f.FarmName, line.LineName, line.ProductionLineID

order by f.FarmID

FineReport 胡桂丹 发布于 2021-11-18 17:01
1min目标场景问卷 立即参与
回答问题
悬赏:5 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
杨朝健Lv5中级互助
发布于2021-11-18 17:36

把问题描述清楚一点

  • 胡桂丹 胡桂丹(提问者) 参数有日,周,月,季度,年,我要怎么改这个sql,才可以在帆软里面正常设置这些参数
    2021-11-18 17:50 
  • 2关注人数
  • 334浏览人数
  • 最后回答于:2021-11-18 17:36
    请选择关闭问题的原因
    确定 取消
    返回顶部