本月执行第一段sql,其他月执行第二段sql

有参数$edate

值形如2023-11

当前月为2023-11

如果参数为2023-11就执行

select *

from xx

where 1=1

and date = '${edate}'

如果参数为其他就执行

select *

from xx

where 1=1

and aaa

and date ='${edate}'

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

${if(edate=left(today(),7),

"select *

from xx

where 1=1

and date = '"+edate+"'",

"select *

from xx

where 1=1

and aaa

and date ='"+edate+"'"

)}

最佳回答
0
CD20160914Lv8专家互助
发布于2023-11-15 16:43(编辑于 2023-11-15 16:44)

select * from XXX表

where 1=1

${if(edate="2023-11","and date='"+edate+"'","and aaa and date='"+edate+"'")}

最佳回答
0
快乐星光Lv5中级互助
发布于2023-11-15 16:44

select *

from xx

where 1=1

and date = '${edate}'

${if(edate='2023-11',"and aaa","")}

'2023-11'可以用一个参数代替,在参数里面做today公式变形

最佳回答
0
kalashangLv3高级互助
发布于2023-11-15 16:44

select *

from xx

where 1=1

and date = '${edate}' ${if(FORMAT(TODAY(),"yyyy-MM")=edate,""," and 1<>1")}

union all

select *

from xx

where 1=1

and aaa

and date ='${edate}' ${if(FORMAT(TODAY(),"yyyy-MM")=edate," and 1<>1","")}

最佳回答
0
touyuan001Lv6中级互助
发布于2023-11-15 16:46

${if(edate="2023-11","and 1=1","and 1=2")}

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