sql语句在FineReport运行报错,生成执行sql拿到数据库运行就没有问题

mysql数据库

image.png

image.png

image.png

WITH t1 as (

SELECT ttu_mobile,ttu_id,ttu_name,

ttu_role,TTU_BUSINESS_TYPE,TTU_STATUS,

REPLACE ( ttu_name,"'","") as xsdb,-- 销售代表,

REPLACE ( TTU_SUPERIOR_NAME,"'","") as dbld -- 代表领导 

FROM total_user 

WHERE TTU_ROLE = 'SE' AND ttu_name IS NOT NULL 

AND TTU_STATUS = '1' 

),t2 as (

SELECT REPLACE( ttu_name,"'","") as xsjl,-- 销售经理,

REPLACE ( TTU_SUPERIOR_NAME, "'","") as jlld -- 经理领导 

FROM total_user 

WHERE TTU_ROLE = 'ASM' AND ttu_name IS NOT NULL 

AND TTU_STATUS = '1' 

GROUP BY ttu_name,TTU_SUPERIOR_NAME 

),t3 as (

SELECT 

REPLACE(ttu_name,"'","") as xstd, -- 销售团队,

REPLACE (TTU_SUPERIOR_NAME,"'","") as tdld --  团队领导 

FROM total_user 

WHERE TTU_ROLE = 'RSD' AND ttu_name IS NOT NULL 

AND TTU_STATUS = '1' 

GROUP BY ttu_name,TTU_SUPERIOR_NAME

),t4 as (

select 

t1.ttu_mobile,

t1.ttu_id,

t1.ttu_name,

t1.ttu_role,

t1.TTU_BUSINESS_TYPE,

t1.TTU_STATUS,

t3.xstd,

t2.xsjl,

t1.xsdb

from t1 left join t2 on t1.dbld = t2.xsjl

left join t3 on t2.jlld = t3.xstd

where t3.xstd is not null

),t5 as (

select 

dealer_code,

sum(ifnull(target_cust_num,0))as target_cust_num

from dm_dbp_cusnum_year_proline_custype

where 1=1

${if(ROUNDUP(MONTH(sdate)/3,0)!=ROUNDUP(MONTH(edate)/3,0),"and 1=0",if(RIGHT(sdate,2)=="01","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="02","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="03","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="04","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="05","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="06","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="07","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="08","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="09","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="10","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')",if(RIGHT(sdate,2)=="11","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')"))))))))))))}

group by dealer_code

),t6 as (

select 

dealer_code,

sum(ifnull(cust_num,0))as cust_num

from dm_act_cusnum_year_proline_custype

where 1=1

${if(ROUNDUP(MONTH(sdate)/3,0)!=ROUNDUP(MONTH(edate)/3,0),"and 1=0",if(RIGHT(sdate,2)=="01","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="02","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="03","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="04","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="05","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="06","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="07","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="08","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="09","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="10","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')",if(RIGHT(sdate,2)=="11","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')"))))))))))))}

group by dealer_code

),t7 as (

SELECT 

dealer_code,

sum(prj_index_value) PVALUE

FROM dm_dbp_mkt_support

WHERE  1=1

${if(ROUNDUP(MONTH(sdate)/3,0)!=ROUNDUP(MONTH(edate)/3,0),"and 1=0",if(RIGHT(sdate,2)=="01","and ym =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="02","and ym =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="03","and ym =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="04","and ym =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="05","and ym =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="06","and ym =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="07","and ym =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="08","and ym =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="09","and ym =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="10","and ym =  CONCAT(left('"+sdate+"',4),'-','4')",if(RIGHT(sdate,2)=="11","and ym =  CONCAT(left('"+sdate+"',4),'-','4')","and ym =  CONCAT(left('"+sdate+"',4),'-','4')"))))))))))))}

GROUP BY dealer_code

),t8 as (

SELECT 

dealer_code,

sum(prj_index_value) APVALUE

FROM dm_act_year_mkt_support

WHERE 1=1

${if(ROUNDUP(MONTH(sdate)/3,0)!=ROUNDUP(MONTH(edate)/3,0),"and 1=0",if(RIGHT(sdate,2)=="01","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="02","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="03","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="04","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="05","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="06","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="07","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="08","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="09","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="10","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')",if(RIGHT(sdate,2)=="11","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')"))))))))))))}

GROUP BY dealer_code

),t9 as (

SELECT 

dealer_code,

sum(prj_index_value) LPVALUE

FROM dm_act_year_mkt_support

WHERE 1=1

${if(ROUNDUP(MONTH(sdate)/3,0)!=ROUNDUP(MONTH(edate)/3,0),"and 1=0",if(RIGHT(sdate,2)=="01","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="02","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="03","and quarter =  CONCAT(left('"+sdate+"',4),'-','1')",if(RIGHT(sdate,2)=="04","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="05","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="06","and quarter =  CONCAT(left('"+sdate+"',4),'-','2')",if(RIGHT(sdate,2)=="07","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="08","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="09","and quarter =  CONCAT(left('"+sdate+"',4),'-','3')",if(RIGHT(sdate,2)=="10","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')",if(RIGHT(sdate,2)=="11","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')","and quarter =  CONCAT(left('"+sdate+"',4),'-','4')"))))))))))))}

GROUP BY dealer_code

)

select 

sum(b.target_sell_in_volumn) as 采购目标

from (

select 

a.xstd,

a.xsjl,

a.xsdb,

a.dtb_code,

a.dtb_cname,

sum(ifnull(a.target_sell_in_volumn,0))as target_sell_in_volumn

from(

select 

t4.*,

d.dtb_code,

d.dtb_cname,

ddsy.year,

ddsy.pro_series_code,

ddsy.pro_line_name,

ddsy.target_sell_in_volumn,

dp.pro_product_labeling

from t4 left join (select distinct dtb_code,DTB_CNAME,DTB_CREATE_USER from distributor where DTB_STATUS = 1) d on t4.ttu_mobile = d.DTB_CREATE_USER

left join dm_dbp_sellin_year_proseries ddsy on d.dtb_code = ddsy.dealer_code and ddsy.year = left('${sdate}',4)

left join  (select distinct d.pro_series_code ,d.pro_line_name,pro_product_labeling from dim_product d  where d.pro_series_code is not null and d.pro_line_name is not null) dp

on dp.pro_series_code = ddsy.pro_series_code

)a 

where 1=1

${if(len(product)=0,"","and pro_line_name in('"+product+"')")}

${if(len(pro_product_labeling)=0,"","and pro_product_labeling in('"+pro_product_labeling+"')")}

group by a.xstd,a.xsjl,a.xsdb,a.dtb_code,a.dtb_cname

)b left join t5 on b.dtb_code = t5.dealer_code

left join t6 on b.dtb_code = t6.dealer_code

left join t7 on b.dtb_code = t7.dealer_code

left join t8 on b.dtb_code = t8.dealer_code

left join t9 on b.dtb_code = t9.dealer_code

where 1=1

${if(len(XSTD)=0,"","and xstd in('"+XSTD+"')")}

${if(len(XSJL)=0,"","and xsjl in('"+XSJL+"')")}

${if(len(XSDB)=0,"","and xsdb in('"+XSDB+"')")}

${if(len(JXS)=0,"","and dtb_code in('"+JXS+"')")}

FineReport 旧友 发布于 2024-6-12 17:27 (编辑于 2024-6-12 17:35)
1min目标场景问卷 立即参与
回答问题
悬赏:9 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2024-6-12 17:31(编辑于 2024-6-12 17:34)

严重怀疑 IN里面的格式不是如下设置

image.png

-------

日志级别改成debug后再预览模板,报错后去日志提取带参数值后的SQL

image.png

  • 旧友 旧友(提问者) 问题在于我只测试了日期判断的参数,其他参数我都没去测试
    2024-06-12 17:34 
  • 旧友 旧友(提问者) 好的,我试试
    2024-06-12 17:35 
  • Z4u3z1 Z4u3z1 回复 旧友(提问者) 参考上面补充的,去日志提取带参值后的SQL查看
    2024-06-12 17:36 
  • 旧友 旧友(提问者) 回复 Z4u3z1 远程环境,但是在我本地上运行就没问题,不知道什么原因
    2024-06-12 18:24 
  • Z4u3z1 Z4u3z1 回复 旧友(提问者) 数据库版本是 不是一样的?帆软的版本是不是一样的
    2024-06-12 18:33 
最佳回答
0
runnerLv7资深互助
发布于2024-6-12 17:29

参数写的有问题吧,你参数给个默认值,看一下sql

  • 旧友 旧友(提问者) 用默认值生成了一个可执行的sql,然后去数据库运行,没有问题
    2024-06-12 17:31 
最佳回答
0
旧友Lv5见习互助
发布于2024-6-17 10:04(编辑于 2024-6-17 10:06)

语句里面有个逗号有问题,但是在本地连接远程的数据库运行又可以运行,放在远程服务器上运行又不行,搞不懂这个,唉

  • 1关注人数
  • 388浏览人数
  • 最后回答于:2024-6-17 10:06
    请选择关闭问题的原因
    确定 取消
    返回顶部