我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[Performance]
@startdate NVARCHAR(100),
@enddate NVARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT
l.LocName
,v.Vtype
,SUM(DATEDIFF(MI, t.Paydate, t.DelDate)) AS TotalDiff
,CONVERT(DECIMAL(10, 1), AVG(CONVERT(NUMERIC(18, 2), DATEDIFF(MI, t.Paydate, t.DelDate)))) AS Average
FROM Transaction_tbl t
LEFT JOIN VType_tbl v ON t.vtid = v.vtid
LEFT JOIN Location_tbl l ON t.Locid = l.Locid
WHERE t.Locid IN
(
SELECT t1.Locid
FROM Transaction_tbl t1
)
AND dtime BETWEEN '' + @startdate + '' AND '' + @enddate + ''
AND status >= 5
GROUP BY
v.Vtype
,l.LocName
,l.Locid
ORDER BY l.Locid
END
LocName Vtype TotalDiff Average
Fashion Avenue VIP 84 2.1
Fashion Avenue Normal 14007 200.1
Address Hotel Normal 33169 1745.7
在这个输出中,我的平均值以分钟为单位显示,我想以 HH:MM(小时,分钟)显示平均值,所以我编写了单独的存储过程来获取小时和分钟的平均值,该存储过程是这样的:
ALTER PROCEDURE [dbo].[test] @locid INT
AS
BEGIN
DECLARE
@Mns DECIMAL
,@dec DECIMAL
SELECT @dec = AVG(CONVERT(NUMERIC(18, 2), DATEDIFF(MI, t.Paydate, t.DelDate)))
FROM Transaction_tbl t
WHERE Locid = @locid;
SELECT @Mns = @dec % 60;
SELECT Avearge =
CONVERT(VARCHAR(10), (CONVERT(DECIMAL(10), @dec / 60))) + ':'
+ CONVERT(VARCHAR, @Mns)
END
这里我出来了 像这样:平均 29:6。在第一个存储过程中获取平均值..我想在我的第一个存储过程中显示这个平均值..那么我如何在第一个存储过程中编写这个存储过程,或者有没有其他方法来获得这个平均值在第一个存储过程中