2017-03-17 116 views
0

我有一個SSRS報告,可以選擇運行兩個日期範圍。Oracle NVL()和SSRS/Visual Studio 2015的數據問題

如果它是從Web瀏覽器中的報表管理器中運行的,則用戶可以在日期下拉列表中指定開始日期和結束日期。

對於報告訂閱,隱藏參數指定日期應該取決於參數。這可能是今天的日期,上週等

報告數據的查詢,我們使用:

between nvl(:i_start_date,:subscription_start_date) and nvl(:i_stop_date,:subscription_stop_date) 

這個工作在SSRS 2012和Visual Studio 2010年。不過,我收到在SSRS以下錯誤2016和Visual Studio 2015:

ORA-01830:轉換整個輸入串

如果我們取出NVL()之前的日期格式圖像結束時,或在nvl中使用非參數化值,則不會發生該問題。例如:

and cr.contact_date between :i_start_date and :i_stop_date -- works, but only for report manager web runs 
and cr.contact_date between :subscription_start_date and :subscription_stop_date -- works, but only for subscriptions 
and cr.contact_date between nvl(:i_start_date,sysdate) and nvl(:i_stop_date,sysdate) -- works, but obviously not using the parameter date. 

爲什麼使用nvl()會導致此日期圖片錯誤?就好像日期/時間類型沒有從SSRS正確傳遞到Oracle查詢中。

將所有日期參數設置爲日期/時間,訂閱參數返回使用CDate()轉換爲日期的值。



下面是訂閱開始參數的代碼。訂閱站是相似的:

=CDate(switch(
Parameters!SubscriptionParam.Value=0, DateSerial(1990,1,1) , 
Parameters!SubscriptionParam.Value=1,today(), 
Parameters!SubscriptionParam.Value=2,dateadd("d",-1,today()), 
Parameters!SubscriptionParam.Value=3,dateadd("d",-7,today()), 
Parameters!SubscriptionParam.Value=4,DateSerial(Year(today()), Month(today()) - 1, 1) 
)) 

0 =免費,1 =昨天,2 =如今,3 =上週,4 =上個月。 返回的日期是正確的。

回答

0

我找不到反正讓上面的代碼工作,所以我轉換的代碼如下:

and (
    (:SubscriptionParam = 0 and cr.contact_date between nvl(:i_start_date,'01-JAN-1900') and nvl(:i_stop_date, sysdate)) 
    or 
    (:SubscriptionParam <> 0 and cr.contact_date between nvl(:subscription_start_date, '01-JAN-1900') and nvl(:subscription_stop_date, sysdate)) 
)