[英]I need help making the code split the sentence. where would I input the split function in my code
[英]Need Help on SSRS SPLIT function
大家好我需要你的建議,
1)我有一個動態字符串,每次都會改變。
例如,今天字符串將是"ItemA,ItemB,ItemC"
,明天它將只是"itemA,ItemB"
。
2)我有一份包含3列的SSRS報告
3)我想將此字符串"ItemA,ItemB,ItemC"
並希望在ssrs表的這3列中顯示拆分子字符串。 分隔符是","
(逗號)
4)我用過
=Split("ItemA,ItemB,ItemC",",").GetValue(0) in the first column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(1) in the second column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(2) in the third column of the report
5)一切正常,直到我的字符串是"ItemA,ItemB,ItemC"
,
但是當我的STRING "ItemA,ItemB"
我在第三列中看到"#Error"
。
我理解錯誤了
=Split("ItemA,ItemB,ItemC",",").GetValue(2)
我們沒有任何值,因為在應用split函數后,字符串現在只有2個值。
有什么辦法可以避免在第三列中出現#Error
。
注意:我必須在ssrs報告中強制使用3列。
我曾嘗試在第三列中使用=Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL")
,但這也無效。
這類似於使用IIF語句中的除零問題 。 問題是IIF不是表達式,它是一個具有三個參數的函數:
IIF(Condition, ValueIfTrue, ValueIfFalse)
因此,在傳遞給函數之前評估所有參數,這導致錯誤,因為即使條件應該意味着它不是,仍然評估錯誤表達。
我無法看到一種方法來使用通常的解決方法來解決除零情況下的問題。 我們需要的是一種沒有這個問題的真實語言。 幸運的是,這可以通過自定義代碼的形式獲得。
請執行下列操作:
插入以下代碼:
Public Function ExtractCode(Combined As String, Position As Integer) As String if (Split(Combined, ",").Length >= Position) Then Return Split(Combined, ",").GetValue(Position-1) Else Return "" End If End Function
單擊“確定”並返回到報告
插入以下表達式:
=Code.ExtractCode(Fields!Combo.Value, 3)
值3是要從Combo字段中提取的“列”,因此要獲取第二個“列”,您將使用2.如果該位置沒有列,則返回空字符串。
如果名稱返回錯誤,您可以將第3列的可見性更改為隱藏
您可以附加一個虛擬元素然后拆分:
yourText = "ItemA,ItemB"
item0 = Split(yourText & ",", ",").GetValue(0)
item1 = Split(yourText & ",", ",").GetValue(1)
item2 = Split(yourText & ",", ",").GetValue(2)
item0 = ItemA
item1 = ItemB
item2 =
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.