简体   繁体   English

ssrs表达式中+和&之间的区别

[英]difference between + and & in ssrs expression

I am working on SSRS Report. 我正在编写SSRS报告。

I have one question, what is the difference between + and & in ssrs-expression? 我有一个问题,ssrs-expression中的+&有什么区别?

Please share your answer with short example. 请通过简短示例分享您的答案。 Thanks. 谢谢。

From SSRS operators description in Visual Studio: 从Visual Studio中的SSRS运算符描述:

+ Add two numbers. +加两个数字。 Also used to concatenate two strings. 也用于连接两个字符串。

Example: 例:

=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' */

& Generates a string concatenation of two expressions. &生成两个表达式的字符串连接。

Example: 例:

=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 */

Another useful operator is And (logical/bitwise AND), which may help to solve some tasks. 另一个有用的运算符是And (逻辑/按位与),它可能有助于解决某些任务。

Example: 例:

=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 */

Actually its depends on how you are going to use them. 实际上,这取决于您将如何使用它们。

1.) For Concatenation purpose 1.)用于串联目的

According to MSDN: 根据MSDN:

在此处输入图片说明

  • using & and + for concatenation will result to the same behaviour or output. 使用&+进行串联将导致相同的行为或输出。 It will only concatenates two strings. 它只会连接两个字符串。

Example: 例:

= 1 & 2

Output: 12 输出: 12

= "1" + "2"

Output: 12 输出: 12

2.) For Arithmetic purpose 2.)出于算术目的

According to MSDN: 根据MSDN: 在此处输入图片说明

  • using + for arithmetic purpose will add the two numbers together 使用+进行算术运算会将两个数字加在一起

Example: 例:

= 1 + 2 //(using two numbers)

Output: 3 输出 3

= 1 + "2" //(using a number and a number with quotes)

Output: 3 输出 3
------------------------------------------------------------------------ -------------------------------------------------- ----------------------
Exceptions 例外

Now there are exceptions that an integer and a string is mixed up or with other types 现在有一个例外,整数和字符串混合在一起或与其他类型混合在一起

Example: 例:

= 1 + "two"

Output: #Error -> this is because they are incompatible with each other. 输出: #Error >这是因为它们彼此不兼容。

  • Workaround - use a conversion functions to convert the default data type for a field to the data type needed for calculations or to combine text. 解决方法-使用转换功能将字段的默认数据类型转换为计算或合并文本所需的数据类型。

Example: 例:

= CSTR(1) + "two"

Output: 1two 输出: 1two

There are other more conversion functions which you can use depending on your needs. 您还可以根据需要使用其他转换功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM