根据${type}的值选定查询语句

select 

${type} as 类型,

RegionCnName,

sum(isnull(RealWeight,0))/1000 as weight

from  (

select 

WorkSheetCode,

RegionCnName,

RealWeight,

syear as 年份,

syearmonth AS 月份 ,

SalesCompanyName,

ServiceType

from 

[DW_CAMS].[dbo].[DWD_ORDERS]

where 

ServiceType like '%空运%'

AND RegionCnName IS NOT NULL 

${if(${type} = "年份","and syear between '"+ Y1 +"' and  '"+ Y2 +"' ","and syearmonth between  '" + YM1 + "' and '" + YM2 + "' ")}

) a 

group by 

${type},

RegionCnName

如上述语句  想达到的效果是 当${type} 为 年份时, 则为  and syear between '${Y1}' AND '${Y2}'   当{type} 为 月份时 ,则为 syearmonth between '${YM1}' and '${YM1}'

哪位大神知道怎么写这段语句  ,请不吝赐教!谢谢

FineReport 唐流雨 发布于 2022-5-11 15:35
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2022-5-11 15:38

select 

'${type}' as 类型,

RegionCnName,

sum(isnull(RealWeight,0))/1000 as weight

from  (

select 

WorkSheetCode,

RegionCnName,

RealWeight,

syear as 年份,

syearmonth AS 月份 ,

SalesCompanyName,

ServiceType

from 

[DW_CAMS].[dbo].[DWD_ORDERS]

where 

ServiceType like '%空运%'

AND RegionCnName IS NOT NULL 

${if(type == "年份","and syear between '"+ Y1 +"' and  '"+ Y2 +"' ","and syearmonth between  '" + YM1 + "' and '" + YM2 + "' ")}

) a 

group by 

RegionCnName

  • 1关注人数
  • 256浏览人数
  • 最后回答于:2022-5-11 15:38
    请选择关闭问题的原因
    确定 取消
    返回顶部