0

我在 iReport 的报表查询向导中有以下查询

select docid_fname_pemid.*, MONTHNAME(b.ServicePeriodDate) as month_name,YEAR(b.ServicePeriodDate) as year_name , b.NonLTCMaximumSpecialPayment, b.NonLTCEnrolledPatientOutsideUseTotal, b.NonLTCAccessBonus
from (
select docid_pemid.PEMID, docid_pemid.DoctorID, b.$P{transparency_check})
from (
select DoctorID,PEMID from DoctorPEMMap where PEMID in ($P{PEMID_input}) and StartDate >= $P{StartDate}  and (EndDate <= $P{EndDate} or EndDate <= '0000-00-00') group by PEMID order by PEMID
)docid_pemid   left join  Doctors b on docid_pemid.DoctorID=b.DoctorID
) docid_fname_pemid
left  join DoctorPayments b on docid_fname_pemid.DoctorID=b.DoctorID

&参数,按顺序(参数类,提示是/否,默认值表达式)

1) PEMID_input--> 字符串,提示是,否

2) month_year--> .String,提示是,否

3) transparency_input--> 字符串,提示是,否

4) transparency_check-->字符串,无提示,($P{transparency_input}=="yes" ) ? ("FirstName") : ("AliasFirstName")

5) StartDate-->字符串,无提示,$P{month_year}.split("-")[0]=="April" ? $P{month_year}.split("-")[1].concat("-04-01") : $P{month_year}.split("-")[1].concat("-10-01")

6) EndDate-->字符串,无提示,$P{month_year}.split("-")[0]=="April" ? $P{month_year}.split("-")[1].concat("-09-30") : $P{month_year}.split("-")[1].concat("-03-31")

当我运行报告时,给出以下错误

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near ''FirstName' 
from (     select DoctorID,PEMID from DoctorPEMMap where PEMID in ('21' at line 3     

我认为查询没有得到'b.FirstName'。所以我使用 concat 函数 as concat('b.',$P{transparency_check}),但它不起作用。

我最终想要b.FirstNameb.AliasFirstName像在 mysql 查询中一样。当我手动给出这些术语中的任何一个时,查询运行良好。

我该怎么走?

4

1 回答 1

2

您遇到的问题与 Jasper 插入参数值的方式有关。如果你只使用 $P{PARAMETER NAME},那么我相信它会在编译 SQL 后填充参数。如果使用 $P!{PARAMETER NAME},参数将被视为文字并在编译 SQL 之前填充。这就是当您仅使用 $P 时,Jasper 似乎在参数值周围插入单引号的原因。

所以尝试改变这个:

b.$P{transparency_check}

对此:

b.$P!{transparency_check}

并删除透明度检查后的额外括号。

检查此链接。我认为它比我能解释得更好。

http://community.jaspersoft.com/wiki/using-report-parameters

这是整个代码的样子。我对其进行了格式化以使其更易于阅读。

SELECT  docid_fname_pemid.*, 
        MONTHNAME(b.ServicePeriodDate) as month_name,
        YEAR(b.ServicePeriodDate) as year_name , 
        b.NonLTCMaximumSpecialPayment, 
        b.NonLTCEnrolledPatientOutsideUseTotal, 
        b.NonLTCAccessBonus

FROM 

(
    SELECT docid_pemid.PEMID, docid_pemid.DoctorID, b.$P!{transparency_check}

    FROM
    (
        SELECT  DoctorID,
                PEMID 
        FROM    DoctorPEMMap 
        WHERE   PEMID IN ($P{PEMID_input}) 
                AND StartDate >= $P{StartDate}
                AND (EndDate <= $P{EndDate} or EndDate <= '0000-00-00') 
        GROUP BY PEMID 
        ORDER BY PEMID
    ) docid_pemid   

    left join  Doctors b on docid_pemid.DoctorID=b.DoctorID

) docid_fname_pemid

left  join DoctorPayments b on docid_fname_pemid.DoctorID=b.DoctorID
于 2012-12-13T19:05:14.117 回答