我有一个这样的存储过程:
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);
; WITH cnt AS
(
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)
),
del AS
(
SELECT
e.ecode,
Cast(q.dtime AS DATE) AS Date,
e.ename,
Count(q.delecode) CntDelEcode
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)
)
SELECT
del.ecode, del.[Date], del.ename,
ISNULL(cnt.cntEcode, 0) CntEcode,
ISNULL(del.CntDelEcode, 0) AS CntDelEcode
FROM
cnt
FULL JOIN
del ON del.ecode = cnt.ecode AND del.[Date] = cnt.[Date]
AND del.Ename = cnt.Ename
end
当我执行这个时,我得到的是null日期和员工姓名。我这样做了:
Ecode Date Ename cntEcode cntDelEcode
--------------------------------------------------
null null null 10 0
null null null 2 0
我的存储过程出了什么问题?我正在加入两张桌子