我正在尝试将值放入html表中。有两个数据库表,我需要从中获取值并显示在html表中。
我写了一个存储过程,但它不起作用。
场景:
用户需要输入季度和年份。根据提供的输入,我将得到一个汇总表。摘要表应包含列:ID,Project,S1,P1。
从数据库表ProjectDetails
检索ID和项目,S1,P1来自Details
例如: 表格如下:
项目详情:
ID | Project
------------------------
PR_1 | the project
PR_2 | the second project
详情表:
PR_1项目
Item | Status | Amount
ABC | S1 | 1000.00
XYZ | S1 | 200.00
Test1| S1 | 300.00
Test2| P1 | 4000.00
所以摘要表应该是:
ID | Project | S1 | P1
PR1| the project | 1500| 4000
PR2| the second project | 0 | 0
这是存储过程:
create proc [dbo].[Summary]
@Quarter int,
@Year int
AS
BEGIN
Declare @S1 AS decimal(18,0)
Declare @P1 AS decimal(18,0)
SELECT BD.ID, BD.Project,Status,((Select SUM(Amount)from Details where Status='S1') as 'S1'), ((Select SUM(Amount) from Details where Status='P1') as 'P1')
FROM ProjectDetails (NOLOCK) BD
inner join Details (NOLOCK) D on BD.Project = D.Project
WHERE BD.Quarter = @Quarter and BD.Year = @Year and BD.Project = D.Project
Group By BD.LineID, BD.Project,Status
END
答案 0 :(得分:0)
create proc [dbo].[Summary]
@Quarter int,
@Year int
AS
BEGIN
Declare @SC AS decimal(18,0)
Declare @PO AS decimal(18,0)
Declare @INV AS decimal(18,0)
SELECT BD.ID, BD.Project,Status,(Select SUM(Amount)from Details a where Status='S1' and BD.Project = a.Project) as S1, (Select SUM(Amount) from Details b where Status='P1' and BD.Project = b.Project) as P1
FROM ProjectDetails (NOLOCK) BD
inner join Details (NOLOCK) D on BD.Project = D.Project
WHERE BD.Quarter = @Quarter and BD.Year = @Year and BD.Project = D.Project
Group By BD.LineID, BD.Project,Status
END
希望这有帮助,我在你的内部查询中添加了缺失的条件
答案 1 :(得分:0)
sucess: function(data){}