ssrs 表达式中 + 和 & 的区别
difference between + and & in ssrs expression
我正在处理 SSRS 报告。
我有一个问题,ssrs-expression中的+
和&
有什么区别?
请用简短的例子分享您的答案。谢谢
来自 Visual Studio 中的 SSRS 运算符描述:
+
添加两个数字。也用于连接两个字符串。
示例:
=Fields!NumberCarsOwned.Value + 2
/* if NumberCarsOwned=10, result: 10 + 2 = 12 */
=Fields!String1.Value + Fields!String2.Value
/* if String1='curious' and String2 ='guy', result: 'curiousguy' */
="4" + 5
/* result: 9, implicit conversion of the first expression */
="a" + 5
/* error: incorrect input string format */
="a" + CStr(5)
/* result: a5 */
="a" + Str(5)
/* result: a 5, space between 'a' and '5' */
&
生成两个表达式的字符串连接。
示例:
=Fields!FirstName.Value & Fields!LastName.Value
/* if FirstName='curious' and LastName='guy', result: 'curiousguy' */
=4 & 5
/* it's concatenation anyway, result: 45 */
=CInt(4) & CInt(5)
/* even explicit cast to integer it's concatenation anyway, result: 45 */
另一个有用的运算符是And
(logical/bitwise AND),它可能有助于解决一些任务。
示例:
=4 And 5
/* result: 4, since 4 (100 binary) And 5 (101 binary) = 4 (100 binary) */
="4" And "5"
/* result: 4 */
="a" And "b"
/* error: incorrect input string format */
实际上这取决于您将如何使用它们。
1.) 用于串联目的
根据 MSDN:
- 使用
&
和 +
进行串联将导致相同的行为或输出。它只会连接两个字符串。
示例:
= 1 & 2
输出: 12
= "1" + "2"
输出: 12
2.) 用于算术目的
根据 MSDN:
- 使用
+
进行算术运算会将两个数字相加
示例:
= 1 + 2 //(using two numbers)
输出: 3
= 1 + "2" //(using a number and a number with quotes)
输出: 3
-------------------------------------------- --------------------------
异常
现在有整数和字符串混合或与其他类型混合的例外情况
示例:
= 1 + "two"
输出: #Error
-> 这是因为它们彼此不兼容。
- 解决方法 - 使用转换函数将字段的默认数据类型转换为计算所需的数据类型或合并文本。
示例:
= CSTR(1) + "two"
输出: 1two
还有其他 conversion functions 可以根据需要使用。
我正在处理 SSRS 报告。
我有一个问题,ssrs-expression中的+
和&
有什么区别?
请用简短的例子分享您的答案。谢谢
来自 Visual Studio 中的 SSRS 运算符描述:
+
添加两个数字。也用于连接两个字符串。
示例:
=Fields!NumberCarsOwned.Value + 2
/* if NumberCarsOwned=10, result: 10 + 2 = 12 */
=Fields!String1.Value + Fields!String2.Value
/* if String1='curious' and String2 ='guy', result: 'curiousguy' */
="4" + 5
/* result: 9, implicit conversion of the first expression */
="a" + 5
/* error: incorrect input string format */
="a" + CStr(5)
/* result: a5 */
="a" + Str(5)
/* result: a 5, space between 'a' and '5' */
&
生成两个表达式的字符串连接。
示例:
=Fields!FirstName.Value & Fields!LastName.Value
/* if FirstName='curious' and LastName='guy', result: 'curiousguy' */
=4 & 5
/* it's concatenation anyway, result: 45 */
=CInt(4) & CInt(5)
/* even explicit cast to integer it's concatenation anyway, result: 45 */
另一个有用的运算符是And
(logical/bitwise AND),它可能有助于解决一些任务。
示例:
=4 And 5
/* result: 4, since 4 (100 binary) And 5 (101 binary) = 4 (100 binary) */
="4" And "5"
/* result: 4 */
="a" And "b"
/* error: incorrect input string format */
实际上这取决于您将如何使用它们。
1.) 用于串联目的
根据 MSDN:
- 使用
&
和+
进行串联将导致相同的行为或输出。它只会连接两个字符串。
示例:
= 1 & 2
输出: 12
= "1" + "2"
输出: 12
2.) 用于算术目的
根据 MSDN:
- 使用
+
进行算术运算会将两个数字相加
示例:
= 1 + 2 //(using two numbers)
输出: 3
= 1 + "2" //(using a number and a number with quotes)
输出: 3
-------------------------------------------- --------------------------
异常
现在有整数和字符串混合或与其他类型混合的例外情况
示例:
= 1 + "two"
输出: #Error
-> 这是因为它们彼此不兼容。
- 解决方法 - 使用转换函数将字段的默认数据类型转换为计算所需的数据类型或合并文本。
示例:
= CSTR(1) + "two"
输出: 1two
还有其他 conversion functions 可以根据需要使用。