2017-03-02 78 views
0

我一直在努力解決這個問題,但我無法一直哼唱。我在這裏回顧了很多問題,但沒有人有我遇到的確切問題。所以,我希望這裏有人能夠提供幫助。如何在SSRS表達式中組合多個AND和OR?

我有一個查詢,它在SSMS中完美運行。但是,這個查詢將被提供給一個報告。該報告具有2個參數,即開始日期和結束日期,由用戶在運行時提供。我需要對這些日期進行一系列檢查,並且只回退符合多個標準之一的記錄,因此是OR。

我想在過濾器中這樣做,併爲每個條件添加一個過濾器。但是,過濾器之間的默認行爲是AND,我需要在我的複雜過濾器之間執行OR操作。所以我在網上找到了一個例子,並開始打字。

OR兩側的表達式獨立工作。但是,只要將它們與OR運算符結合使用,我只會返回與OR前面(OR之前)匹配的記錄,但不包含匹配背面(OR之後)的記錄。

這是動態CRM 2015年的一份報告,而且我在使用Visual Studio 2010中

這裏是我已經把報表上的過濾器的截圖: Screenshot of Filter

這是裏面的表達這個過濾器:

=((Fields!xyz_StartDateNewStudent.Value <> Nothing) AND (Fields!xyz_StartDateNewStudent.Value >= Parameters!StartDate.Value) AND (Fields!xyz_StartDateNewStudent.Value <= Parameters!EndDate.Value)) Or ((Fields!xyz_StartDateCarryoverStudent.Value <> Nothing) AND (Fields!xyz_StartDateCarryoverStudent.Value <= Parameters!StartDate.Value) AND (Fields!xyz_GraduationDate.Value <> Nothing) AND (Fields!xyz_GraduationDate.Value <= Parameters!EndDate.Value)) 

任何人都可以說明爲什麼我的OR不能在兩端的方程?

回答

2

不幸的是,SSRS表達式不喜歡布爾邏輯。您需要使用IIF:

=IIF((Fields!xyz_StartDateNewStudent.Value <> Nothing) 
    AND (Fields!xyz_StartDateNewStudent.Value >= Parameters!StartDate.Value) 
    AND (Fields!xyz_StartDateNewStudent.Value <= Parameters!EndDate.Value)) 
Or ((Fields!xyz_StartDateCarryoverStudent.Value <> Nothing) 
    AND (Fields!xyz_StartDateCarryoverStudent.Value <= Parameters!StartDate.Value) 
    AND (Fields!xyz_GraduationDate.Value <> Nothing) 
    AND (Fields!xyz_GraduationDate.Value <= Parameters!EndDate.Value)) 
, True, False) 
+0

謝謝,漢諾威!在玩了一段代碼後(錯位的括號),然後確保我輸入的日期範圍能夠滿足我的兩個要求,我相信我已經按預期發射了這個東西。 –

+0

過濾Expr的:!! 「= IIF((字段mids_StartDateNewStudent.Value <>爲Nothing) AND(字段mids_StartDateNewStudent.Value> =參數StartDate.Value) AND(字段mids_StartDateNewStudent.Value <=結束日期參數!值) 或者 ((領域!mids_StartDateCarryoverStudent.Value <>爲Nothing) AND(領域!mids_StartDateCarryoverStudent.Value <=參數!StartDate.Value) AND(領域!mids_GraduationDate.Value <>爲Nothing) AND(領域!mids_GraduationDate .Value <= Parameters!EndDate.Value)) ,True,False)' –

+0

只是想 - 這是正確的嗎? 'Fields!mids_GraduationDate.Value <> Nothing'。我似乎記得有些東西沒有在比較中工作,你需要使用'NOT ISNOTHING(Fields!mids_GraduationDate.Value)'。如果您缺少某些東西,請檢查您的結果。 –