vb.net 如何根据RDLC报告中另一个字段中的条件对字段求和?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29642065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to sum a field based on a condition in another field in RDLC report?
提问by Muhammad Tarique
I have an SQL database with skunoand qtycolumns, with the varchar(50)data type and an intdata type respectively.
我有一个带有skuno和qty列的 SQL 数据库,分别具有varchar(50)数据类型和int数据类型。
Here are the columns :
以下是列:
skuno qty
-----------------
78654 - 100
65495 - 120
10564 - 67
64389 - 20
I want to sum qtywhere skunobegins with a "6" in rdlc report.
我要总结qty,其中skuno有一个“6”在RDLC报告开始。
I am using this expression but getting an error :
我正在使用这个表达式,但收到一个错误:
=Sum(iif(Fields!skuno.Value like "6*", Fields!qty.Value, 0))
Where is the problem and how can I fix it?
问题出在哪里,我该如何解决?
回答by tezzo
You can use an expression like this:
您可以使用这样的表达式:
=Sum(CInt(IIf(Left(Fields!skuno.Value, 1) = "6", Fields!qty.Value, 0)))
Please note that you have to convert every possible values to the same type (CInt for Integer, CDec for Decimal, CDbl for Double, etc.) before aggregation.
请注意,在聚合之前,您必须将所有可能的值转换为相同的类型(CInt 表示整数,CDec 表示小数,CDbl 表示双精度,等等)。

