数据库里面通过CASETHEN新增SEQ,控件查询时数据字典用数据查询ds1里面的SEQ,查不出

WXWorkLocal_16880938608468.png

WXWorkLocal_168809362242.png

FineReport 用户eddWx1221283 发布于 2023-6-30 10:57
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
CD20160914Lv8专家互助
发布于2023-6-30 10:59(编辑于 2023-6-30 11:00)

你要在外面再套一层

select t.*  from (你原来的sql )t 

where  t.seq='${参数名称}'

  • 用户eddWx1221283 用户eddWx1221283(提问者) 不可以啊,报错了
    2023-06-30 11:17 
  • CD20160914 CD20160914 回复 用户eddWx1221283(提问者) 你在设计器里面先预览看报什么错误,你是什么数据库
    2023-06-30 11:18 
  • 用户eddWx1221283 用户eddWx1221283(提问者) 回复 CD20160914 DB2
    2023-06-30 11:31 
  • 用户eddWx1221283 用户eddWx1221283(提问者) 回复 CD20160914 报错-206
    2023-06-30 11:31 
  • 用户eddWx1221283 用户eddWx1221283(提问者) 是不是我加的位置错了,麻烦你帮我加一下 select a.cpi_id,a.inspecttime,a.INSPECTIONTYPEID,a.product_date,a.team_id,a.remark,a.MATERIAL_ID,a.inspect_num,b.NAME,d.max,d.min,d.avg,d.sd,d.cv,d.over_num,e.name AS name2,e.id,(case d.PARAMETERID when 10524200 then 1 when 300323 then 2 when 300320 then 3 when 300322 then 4 when 300326 then 5 when 10524202 then 6 when 300321 then 7 end ) as SEQ, (case a.remark when \'.1\' then \'硬1#\' when .2 then \'硬2#\' when .3 then \'硬3#\' when .4 then \'硬4#\' when .5 then \'硬5#\' when .6 then \'硬6#\' when .7 then \'硬7#\' when .8 then \'硬8#\' when .9 then \'硬9#\' when .10 then \'硬10#\' when .11 then \'硬11#\' when .12 then \'硬12#\' when 01 then \'软1#\' when 02 then \'软2#\' when 03 then \'软3#\' when 04 then \'软4#\' when 05 then \'软5#\' when 06 then \'软6#\' when 07 then \'软7#\' when 08 then \'软8#\' when 09 then \'软9#\' when 10 then \'软10#\' else \'其它\' end) as machinename FROM QUA.CIGARETTE_PHYS_SCENE a, PUB.EQUIPMENT b, QUA.CIGARETTE_PHYS_SCENE_PARA d, PUB.LOGICPARAMETER e WHERE 1=1 ${if(len(班次) == 0,\"\",\"and a.team_id = \'\" +班次 + \"\'\")} and 1=1 ${if(len(类型) == 0,\"\",\"and a.INSPECTIONTYPEID = \'\" +类型 + \"\'\")} and 1=1 ${if(len(牌号) == 0,\"\",\"and a.MATERIAL_ID = \'\" +牌号 + \"\'\")} and 1=1 ${if(len(机台) == 0,\"\",\"and seq = \'\" +机台 + \"\'\")} and 1=1 ${if(len(ID) == 0,\"\",\"and a.cpi_id = \'\" +ID + \"\'\")} and a.EQUIPMENT_ID=b.id AND d.PARAMETERID=e.id and a.cpi_id=d.cpi_id and a.inspect_num=\'20\' order by INSPECTTIME DESC
    2023-06-30 11:33 
最佳回答
0
snrtuemcLv8专家互助
发布于2023-6-30 11:08

这些数字都用单引号引用试试

when '10524200' then '1'

这个格式

image.png

最佳回答
0
春眠不觉Lv4见习互助
发布于2023-6-30 13:58(编辑于 2023-6-30 14:11)

一楼的想法应该是这个

因为SQL执行顺序的原因,所以你需要嵌套一层子查询

-----------------------------------------------

select t.* from (

select 

  a.cpi_id,a.inspecttime,a.INSPECTIONTYPEID,a.product_date,a.team_id,a.remark,a.MATERIAL_ID,a.inspect_num,b.NAME,

  d.max,d.min,d.avg,d.sd,d.cv,d.over_num,e.name AS name2,e.id,

  (case d.PARAMETERID when 10524200 then 1 

        when 300323 then 2 

          when 300320 then 3 

            when 300322 then 4 

              when 300326 then 5 

                when 10524202 then 6 

                  when 300321 then 7 

                    end ) as SEQ, 

  (case a.remark when \'.1\' then \'硬1#\' 

        when .2 then \'硬2#\' 

          when .3 then \'硬3#\' 

            when .4 then \'硬4#\' 

              when .5 then \'硬5#\'

                 when .6 then \'硬6#\' 

                   when .7 then \'硬7#\' 

                     when .8 then \'硬8#\' 

                       when .9 then \'硬9#\' 

                         when .10 then \'硬10#\' 

                           when .11 then \'硬11#\' 

                             when .12 then \'硬12#\' 

                               when 01 then \'软1#\' 

                                 when 02 then \'软2#\' 

                                   when 03 then \'软3#\' 

                                     when 04 then \'软4#\' 

                                       when 05 then \'软5#\' 

                                         when 06 then \'软6#\' 

                                           when 07 then \'软7#\' 

                                             when 08 then \'软8#\' 

                                               when 09 then \'软9#\' 

                                                 when 10 then \'软10#\' 

                                                   else \'其它\' end) as machinename 

FROM QUA.CIGARETTE_PHYS_SCENE a, PUB.EQUIPMENT b, QUA.CIGARETTE_PHYS_SCENE_PARA d, PUB.LOGICPARAMETER e 

WHERE 1=1 

      ${if(len(班次) == 0,\"\",\"and a.team_id = \'\" +班次 + \"\'\")} and 1=1 

      ${if(len(类型) == 0,\"\",\"and a.INSPECTIONTYPEID = \'\" +类型 + \"\'\")} and 1=1 

      ${if(len(牌号) == 0,\"\",\"and a.MATERIAL_ID = \'\" +牌号 + \"\'\")} and 1=1 

      ${if(len(ID) == 0,\"\",\"and a.cpi_id = \'\" +ID + \"\'\")} and a.EQUIPMENT_ID=b.id 

                   AND d.PARAMETERID=e.id and a.cpi_id=d.cpi_id and a.inspect_num=\'20\' 

                       ) t

                       where 1 = 1 

                             ${if(len(机台) == 0,\"\",\"and t.seq = \'\" +机台 + \"\'\")} and 1=1 

order by t.INSPECTTIME DESC

  • 3关注人数
  • 239浏览人数
  • 最后回答于:2023-6-30 14:11
    请选择关闭问题的原因
    确定 取消
    返回顶部