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

&パラメータ、順番に(パラメータクラス、プロンプトYes/NO、デフォルト値式)

1) PEMID_input--> 文字列、プロンプト はい、いいえ

2) month_year--> .String,prompt はい、いいえ

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 関数を として使用しましconcat('b.',$P{transparency_check})たが、機能しません。

私は最終的にb.FirstName、またはb.AliasFirstNamemysqlクエリのように、手動でこの用語のいずれかを指定すると、クエリは正常に実行されます。

どうやって行けばいいですか?

4

1 に答える 1

2

あなたが抱えている問題は、ジャスパーがパラメーター値を挿入する方法に関係しています。$P{PARAMETER NAME} だけを使用すると、SQL のコンパイル後にパラメーターが入力されると思います。$P!{PARAMETER NAME} を使用すると、パラメーターはリテラルとして扱われ、SQL をコンパイルする前に入力されます。これが、$P のみを使用する場合に Jasper がパラメータ値を一重引用符で囲んでいるように見える理由です。

したがって、これを変更してみてください:

b.$P{transparency_check}

これに:

b.$P!{transparency_check}

そして、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 に答える