2013-07-26 83 views
3

我在做關於SSRS報告的報告。我需要爲Textbox寫一個表達式來顯示不同的輸入參數(如果提供的話)。我曾試着寫下這個表達。但不能完美。在這裏我提供了示例代碼,其中我需要有一個SSRS表達式。任何人都可以幫助我以SSRS格式提供相同的表達。帶有If語句的SSRS表達式

代碼

If(Parameters!FromCreationdate.Value !=null && Parameters!ToCreationdate.Value !=null) 
{ 
    "Created Date:"+ Parameters!FromCreationdate.Value + "To Created Date:"+Parameters!ToCreationdate.Value; 
} 
else if(Parameters!FromCreationdate.Value !=null) 
{ 
    "Created Date:"+ Parameters!FromCreationdate.Value; 
} 
else if(Parameters!ToCreationdate.Value !=null) 
{ 
"To Created Date:"+ Parameters!ToCreationdate.Value; 
} 

表達

=IIf(isnothing(Parameters!FromCreationdate.Value),"", "From Creation Date:"+Parameters!FromCreationdate.Value, iif(isnothing(Parameters!FromCreationdate.Value)),"", "To Creation Date:"+Parameters!FromCreationdate.Value) 

感謝

+0

我看不到您設置TextBox值屬性。發佈你的代碼? – andrewb

回答

4

看一看Expression Examples (Report Builder and SSRS)並且更確切地SWITCH

當您有三個或更多條件 要測試時,開關功能非常有用。該開關函數返回一系列計算結果爲true

的 第一個表達式相關聯的值,因此會使用它像

=SWITCH(
TEST_CONDITION_1,VALUE_1, 
TEST_CONDITION_2,VALUE_2, 
TEST_CONDITION_3,VALUE_3, 
.... 
TEST_CONDITION_N,VALUE_N 
) 
2

使用交換機是一個更好的方法,但是如果你仍然需要/想窩因爲某些原因IIF語句,它會是這樣,而不是:

=IIF(Not IsNothing(Parameters!FromCreationdate.Value) And Not IsNothing(Parameters! ToCreationdate.Value), 
    "Created Date: " + Parameters!FromCreationdate.Value + 
    " To Created Date: " + Parameters!ToCreationdate.Value, 
    IIF(Not IsNothing(Parameters!FromCreationdate.Value), 
     "Created Date: " + Parameters!FromCreationdate.Value, 
     IIF(Not IsNothing(Parameters!ToCreationdate.Value), 
      "To Created Date: " + Parameters!ToCreationdate.Value, 
      "" 
      ) 
     ) 
    ) 

或者,你也可以這樣做:

=IIF(Not IsNothing(Parameters!FromCreationdate.Value), 
    "Created Date: " + Parameters!FromCreationdate.Value, 
    "") + 
IIF(Not IsNothing(Parameters!FromCreationdate.Value) AND 
    Not IsNothing (Parameters!ToCreationdate.Value), 
    " ", "") + 
IIF(Not IsNothing(Parameters!ToCreationdate.Value), 
    "To Created Date: " + Parameters!ToCreationdate.Value, 
    "") 

您可能需要如果要創建於2005年SSRS報告,並部署更改爲空字符串(「」)爲Nothing至2008年這樣做既與某些導出格式(也可能是某些瀏覽器)已經引起當我們在文本字段上設置粗體時,空字符串看起來像一個破折號。