Asp.net 如何显示两个表中的总和(成本)和收入,并每月显示
我有两张桌子:Asp.net 如何显示两个表中的总和(成本)和收入,并每月显示,asp.net,reporting-services,report,Asp.net,Reporting Services,Report,我有两张桌子: table 1: Expense cost 投寄日期 table 2: Employee cost Rvenue 结算日期 Totalcost = Expense cost + Employee cost Pofit Revenue - TotalCost 我必须这样显示报告。它应该根据年份显示每月的数据,比如说2011年,我知道如何按年份过滤 Totalcost | Revenue | Profit jan feb mar apr may jun j
table 1:
Expense cost
投寄日期
table 2:
Employee cost
Rvenue
结算日期
Totalcost = Expense cost + Employee cost
Pofit Revenue - TotalCost
我必须这样显示报告。它应该根据年份显示每月的数据,比如说2011年,我知道如何按年份过滤
Totalcost | Revenue | Profit
jan
feb
mar
apr
may
jun
jul
aug
sep
oct
nov
dec
我很难回答这个问题。
问题是如何在报表查看器表中显示数据最简单的方法是将数据组合成单个数据表,作为报表的数据源 您可以在数据库端连接这两个表-例如
SELECT
t1.Month,
t1.ExpenseCost + t2.EmployeeCost AS TotalCost,
t2.Revenue,
t2.Revenue - t1.ExpenseCost - t2.EmployeeCost AS Profit
FROM
Table1 t1
INNER JOIN Table2 t2 ON t1.Year = t2.Year and t1.Month = t2.Month
WHERE
t1.Year = @Year /* parameter to filter for a year */
或者,您可以使用数据关系或更简单地使用LINQ over data tables在前端组合数据,例如
var query = from t1 in table1.AsEnumerable()
join t1 in table2.AsEnumerable()
on t1.Field<string>("Month") equals t2.Field<string>("Month")
select new
{
Month = t1.Field<string>("Month"),
TotalCost = t1.Field<Decimal>("ExpenseCost") + t2.Field<Decimal>("EmployeeCost"),
Revenue = t2.Field<Decimal>("Revenue"),
// similarly compute profit
};
好的,我得到了查询,但是我如何在reportviewer上显示它,因为我有12个月的时间来填写成本和收入数据profit@nikolomanabal,查询输出已经是所需的格式,您所要做的就是使用表数据区域创建一个RDLC或RDL文件-请参阅