2016-04-12 7 views
1

私はJaspersoftスタジオを使用してレポートを作成しています。データアダプタはpostgresqlクエリ(postgresサーバ)です。クエリ:datetimeパラメータをpostgresql sqlに渡すには?

select * from dbo.FACTSALES where FactSales.saledatekey BETWEEN to_char($P!{StartDate}, 'YYYYMMDD')::INTEGER AND to_char($P!{EndDate}, 'YYYYMMDD')::INTEGER 

FactSales.saledatekeyIntegerです。

私の計画は、レポートに2つのデータ時間パラメータ(StartDate、EndDate)を入れて、レポートを実行する開始日と終了日を選択できるようにすることです。したがって、クエリは上記のとおりで、同じ名前のjava.sql.Timestamp(デフォルトの式はありません)という2つのパラメータをOutlineに作成しました。しかし、私はレポートを実行するとエラーSQLステートメントを実行します。

EDIT

ので、私は$ Pを変えました! 〜$ P

select * from dbo.FACTSALES where FactSales.saledatekey BETWEEN to_char($P{StartDate}, 'YYYYMMDD')::INTEGER AND to_char($P{EndDate}, 'YYYYMMDD')::INTEGER 

しかし、私はまだ同じエラーが発生します。

jrxml(私はちょうど2つの列に*を選択から変更):

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fd68b751-49c2-4153-b2a8-48a95af021c9"> 
     <property name="com.jaspersoft.studio.data.sql.tables" value=""/> 
     <property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/> 
     <property name="ireport.jasperserver.url" value="http://10.20.169.43:8080/jasperserver/"/> 
     <property name="ireport.jasperserver.user" value="Nian"/> 
     <property name="ireport.jasperserver.report.resource" value="/reports/NianTest/test4_files/main_jrxml"/> 
     <property name="ireport.jasperserver.reportUnit" value="/reports/NianTest/test4"/> 
     <parameter name="StartDate" class="java.sql.Timestamp"> 
      <parameterDescription><![CDATA[]]></parameterDescription> 
     </parameter> 
     <parameter name="EndDate" class="java.sql.Timestamp"/> 
     <queryString> 
      <![CDATA[select customerkey, productkey from dbo.FACTSALES where $X{[BETWEEN], FactSales.saledatekey , to_char($P{StartDate} , 'YYYYMMDD')::INTEGER, to_char($P{EndDate}, 'YYYYMMDD')::INTEGER}]]> 
     </queryString> 
     <field name="customerkey" class="java.lang.Integer"/> 
     <field name="productkey" class="java.lang.Integer"/> 
     <background> 
      <band splitType="Stretch"/> 
     </background> 
     <title> 
      <band height="79" splitType="Stretch"/> 
     </title> 
     <pageHeader> 
      <band height="35" splitType="Stretch"/> 
     </pageHeader> 
     <columnHeader> 
      <band height="61" splitType="Stretch"> 
       <staticText> 
        <reportElement x="50" y="0" width="100" height="30" uuid="1471918d-b246-4aea-ba5c-d65a7fa48284"/> 
        <text><![CDATA[customerkey]]></text> 
       </staticText> 
       <staticText> 
        <reportElement x="268" y="0" width="100" height="30" uuid="361e8408-7859-483f-8143-5834fff3594d"/> 
        <text><![CDATA[productkey]]></text> 
       </staticText> 
      </band> 
     </columnHeader> 
     <detail> 
      <band height="125" splitType="Stretch"> 
       <textField> 
        <reportElement x="50" y="49" width="100" height="30" uuid="3423ea0c-aa51-4537-ab28-29ae255c313c"/> 
        <textFieldExpression><![CDATA[$F{customerkey}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement x="200" y="40" width="100" height="30" uuid="d8381278-1fc1-4f9f-bd85-e65a85b77630"/> 
        <textFieldExpression><![CDATA[$F{productkey}]]></textFieldExpression> 
       </textField> 
      </band> 
     </detail> 
     <columnFooter> 
      <band height="45" splitType="Stretch"/> 
     </columnFooter> 
     <pageFooter> 
      <band height="54" splitType="Stretch"/> 
     </pageFooter> 
     <summary> 
      <band height="42" splitType="Stretch"/> 
     </summary> 
</jasperReport> 

と二つのパラメータ:

StartDate class: java.sql.Timestamp 
EndDate class: java.sql.Timestamp 

エラー:

ERROR: function to_char(unknown, unknown) is not unique Hint: Could not choose a best candidate function. You might need to add explicit type casts

+0

あなたの$ P!{StartDate}はjava.sql.Timestampですか?あなたが知っている!あなたは文字列置換をしていますか?さらに、クエリ[using-parameters-queries](http://community.jaspersoft.com/documentation/tibco-jaspersoft-studio-user-guide/v60/using-パラメータ - クエリ) –

+0

私はこれを重複として提案します。http://stackoverflow.com/questions/11871042/jasperreports-passing-parameters-to-query、Alexは答えに$ P {と$ P!{、しかしおそらくあなたの場合、私は$ X {IS_BETWEEN、column、startParam、endParam}を使用したでしょう –

+0

少し詳しく説明できますか?私はこれに本当に新しいです。 – thotwielder

答えて

1

クエリ使用準備された声明は:

select customerkey, productkey from dbo.FACTSALES where FactSales.saledatekey BETWEEN to_char($P{StartDate}::timestamp, 'YYYYMMDD')::int AND to_char($P{EndDate}::timestamp, 'YYYYMMDD')::int 

またはあなたがIDEでテストしたい場合は、常にセットのデフォルト値にパラメータにを検討Integerにパラメータと

select customerkey, productkey from dbo.FACTSALES where $X{[BETWEEN], FactSales.saledatekey ,StartDate, EndDate} 

機能間のビルドでを使用して変更します。

<parameter name="StartDate" class="java.sql.Timestamp" isForPrompting="false"> 
    <defaultValueExpression><![CDATA[new java.sql.Timestamp(1l)]]></defaultValueExpression> 
</parameter> 
<parameter name="EndDate" class="java.sql.Timestamp" isForPrompting="false"> 
    <defaultValueExpression><![CDATA[new java.sql.Timestamp(new java.util.Date().getTime())]]></defaultValueExpression> 
</parameter> 
+0

FactSales.saledatekeyが整数(つまり、20160413)なので、あなたのものは動作しないので、元のクエリでは、比較のために開始日/終了日を整数に変換しています。私は、このdbo.FN_convertIntToDate(saledatekey)> = $ P {StartDate}とdbo.FN_convertIntToDate(saledatekey)<= $ P {EndDate}のようなdatetimeにsalesdatekeyを変換しようとしました。ここで、FN_convertIntToDateは関数で、オリジナルの作品を作る方法を知りたいだけですか? – thotwielder

+0

Aaahその日付形式の整数、私はタイムスタンプ形式(ms)を使用すると、整数のパラメータを使用しますか? –

+0

いいえ、動作しません。私は実際に私の2番目のバージョンでこれを疲れている。このエラーが表示されます。エラー:to_char(unknown、unknown)関数が一意ではありません ヒント:最適な候補関数を選択できませんでした。明示的な型キャストを追加する必要があるかもしれません。 ポジション:87 (データセットとクエリダイアログ)ウィンドウ。 – thotwielder

関連する問題