我有一个这样的存储过程:
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
, (
SELECT COUNT(*)
FROM Transaction_tbl
WHERE dtime >= '' + @date1 + ''
AND dtime <= '' + @date2 + ''
AND DelEcode = @Ecode
GROUP BY CAST(dtime AS DATE)
)
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)
ORDER BY CAST(q.dtime AS DATE)
END
执行此查询时出现如下错误:
子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。