我有这样的存储过程:
ALTER PROCEDURE [dbo].[Driverperformance]
@Ecode NVARCHAR(50),
@startdate DATETIME,
@enddate DATETIME
AS
BEGIN
DECLARE @date1 DATETIME = CONVERT(DATETIME, @startdate + ' 00:01:00.000', 120);
DECLARE @date2 DATETIME = CONVERT(DATETIME, @enddate + ' 23:23:59.000', 120) ;
SELECT
e.ecode,
Cast(q.dtime AS DATE) AS Date,
e.ename,
Count(q.ecode) cntEcode
FROM employeemaster_tbl e JOIN transaction_tbl q ON e.ecode = q.ecode
WHERE
q.ecode = @Ecode
AND dtime >= '' + @date1 + ''
AND dtime <= '' + @date2 + ''
GROUP BY
e.ecode,
e.ename,
Cast(q.dtime AS DATE)
SELECT
e.ecode,
Cast(q.dtime AS DATE) AS Date,
e.ename,
Count(q.delecode) DelEcode
FROM employeemaster_tbl e JOIN transaction_tbl q ON e.ecode = q.delecode
WHERE
q.delecode = @Ecode
AND dtime >= '' + @date1 + ''
AND dtime <= '' + @date2 + ''
GROUP BY
e.ecode,
e.ename,
Cast(q.dtime AS DATE)
ORDER BY Cast(q.dtime AS DATE)
END
我得到第一个结果:
Ecode Date Ename CntEcode
E003 2013-05-05 Raheem 4
E003 2013-05-28 Raheem 1
第二个结果:
Ecode Date Ename CntEcode
E003 2013-05-05 Raheem 3
E003 2013-05-27 Raheem 7
E003 2013-05-28 Raheem 1
但我想得到这样的结果:
Ecode Date Ename CntEcode DelEcode
E003 2013-05-05 Raheem 4 3
E003 2013-05-27 Raheem 0 7
E003 2013-05-28 Raheem 1 1
我怎样才能做到这一点?如果有人知道,请帮助我找出答案。