2014-05-09 79 views
2

我正在研究Crystal Reports XI中的一個報告,該報告允許某人使用大量可選動態參數篩選幫助臺票證。如果我爲每個參數進行選擇,它會返回預期的結果,但是如果省略了任何參數,它將不會返回任何內容,並且當我查看SQL查詢時,它會顯示「沒有SQL查詢被使用,因爲記錄選擇公式不會返回記錄。「目前,我有記錄選擇下面的代碼:使用可選參數篩選Crystal Reports

{Incident.State:} = "C" and 
{Incident.Close Date & Time} in {?BDate} to {?EDate} and 
If HasValue({?Group}) Then (
    {Groups.Code} = {?Group} 
) 
and 
If HasValue({?Category}) Then (
    {Incident.Subject Description} = {?Category} 
) 
and 
If HasValue({?Staff}) Then (
    {Incident_Details.Login ID} = {?Staff} 
) 
and 
If HasValue({?Community}) Then (
    {Incident.Company Name} = {?Community} 
) 

對我來說,這似乎像它應該工作,如果我離開了If語句,以驗證參數的值,我得到一個錯誤,所以它看起來像hasValue的工作正常。有任何想法嗎?

回答

3

您的問題源於未明確處理可選參數配置。在記錄選擇公式中使用if語句時,很容易遇到此問題。相反,顯式處理參數DO和DO不具有值的情況。事情是這樣的:

... 
(not(hasvalue({?Group})) or {Groups.Code}={?Group}) 
and 
(not(hasvalue({?Category})) or {Incident.Subject Description} = {?Category}) 
and 
(not(hasvalue({?Staff})) or {Incident_Details.Login ID} = {?Staff}) 
and 
(not(hasvalue({?Community})) or {Incident.Company Name} = {?Community}) 

這種方式切實做好它告訴CR只是忽略的參數,如果就是不具有價值,否則基於什麼在這些參數輸入選擇記錄。

1

「記錄選擇」公式通過返回true或false來指示是否必須使用記錄。考慮到這一點,如果知道某個值,則該公式必須符合某些條件纔會返回True。如果沒有通知過濾器,則公式必須始終返回True。

嘗試這樣:

{Incident.State:} = "C" and 
{Incident.Close Date & Time} in {?BDate} to {?EDate} and 
(If HasValue({?Group}) Then (
    {Groups.Code} = {?Group} 
) else 
(True)) 
and 
(If HasValue({?Category}) Then (
    {Incident.Subject Description} = {?Category} 
) else 
(True)) 
and (
If HasValue({?Staff}) Then (
    {Incident_Details.Login ID} = {?Staff} 
) else 
(True)) 
and (
If HasValue({?Community}) Then (
    {Incident.Company Name} = {?Community} 
) else 
(True))