【问题标题】:how to show sum(cost) and revenue from two tables and display per month如何显示两个表格的总和(成本)和收入并每月显示
【发布时间】:2011-12-08 00:52:28
【问题描述】:

我有两张桌子:

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

我很难解决这个问题。 问题是如何在报表查看器表中显示数据

【问题讨论】:

    标签: asp.net reporting-services report


    【解决方案1】:

    最简单的方法是将数据组合成一个单独的数据表,作为报告的数据源。

    您可以在数据库端连接两个表 - 例如,

    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 来组合前端的数据 - 例如

    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 个月的时间来填写成本收入和利润数据
    • @nikolomanabal,查询输出已经是所需的格式,您所要做的就是创建一个带有表数据区域的 RDLC(或 RDL)文件 - 请参阅 msdn.microsoft.com/en-us/library/ms251659%28v=VS.90%29.aspx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多