如何在结果集中添加其他行以显示总计?

时间:2012-05-02 22:20:51

标签: asp.net sql tsql

这是我的问题:

SELECT      p.Company
        ,   p.Project_ID
        ,   p.Name as 'Project_Name'
        ,   p.Company
        ,   t.Name as 'Task_Name'
        ,   r.Owner
        ,   t.Status
        ,   r.Work_Date
        ,   r.Minutes_Spent
        ,   r.Type
        ,   r.Description
FROM        TK_Project      p 
INNER JOIN  TK_Task         t
ON          p.Project_ID    = t.Project_ID 
JOIN        TK_Time_Record  r
ON          t.ID            = r.Task_ID
WHERE       p.Company       = 248 
AND         p.Name          = 'Technical Support'
AND         r.Work_Date     BETWEEN  '01/01/2012'  AND  '05/02/2012'
AND         r.Type          NOT LIKE '%non%'
--AND       (
--                  r.Type = 'Programming-Billable' 
--              OR  r.Type = 'Consulting-Billable'
--          )
AND         (
                    r.Type = 'Data Maintenance' 
                OR  r.Type = 'Tech Support-Billable' 
                OR  r.Type = 'Training'
            )
ORDER BY    r.Work_Date DESC

这是它返回的数据:

Company Project_ID Project_Name      Company Task_Name         Owner   Status    Work_Date             Minutes_Spent Type                   Description
------- ---------- ----------------- ------- ----------------- ------- ------- ----------------------- ------------- --------------------- ------------
248     512        Technical Support 248     Technical Support Tim     Started 2012-03-06 00:00:00.000      15       Tech Support-Billable Notes.
248     512        Technical Support 248     Technical Support Patrick Started 2012-02-24 00:00:00.000      15       Data Maintenance      Notes.
248     512        Technical Support 248     Technical Support Tim     Started 2012-02-24 00:00:00.000      15       Tech Support-Billable Notes.
248     512        Technical Support 248     Technical Support Tim     Started 2012-02-14 00:00:00.000      15       Tech Support-Billable Notes.
248     512        Technical Support 248     Technical Support Tim     Started 2012-01-05 00:00:00.000      15       Tech Support-Billable Notes.
248     512        Technical Support 248     Technical Support Tim     Started 2012-01-04 00:00:00.000      15       Tech Support-Billable Notes.

asp.net或sql获取Minutes_Spent列的最佳方法是什么?我试图让WITH ROLLUP工作,但无法让它正常工作。我尝试过COMPUTE,但不能返回多个结果集(也许我可以但不知道如何在asp.net中访问它)

1 个答案:

答案 0 :(得分:1)

考虑到你的问题,我猜副请求不是你想要的 至于asp,我发现这篇文章可能会让你感兴趣,尽管你已经尝试过了:
How to calculate the sum of the datatable column in asp.net?

如果过滤器有问题,请看一下这篇文章:
SUM datatable column with compute but NO filter

我希望它能帮到你!