如果我忽略了一些简单的事情,请原谅我,但是我正在努力解决这个问题。我正在尝试进行计数,当我在SQL中运行以下查询时,我得到的值为21,但是当使用相同的参数运行存储过程时,它会计数20.出了什么问题?
普通查询
(SELECT Count(DISTINCT CONVERT(VARCHAR, f.date_entered, 101))
FROM de_urine f
WHERE f.location = @Location
AND f.date_entered BETWEEN @StartDate AND @EndDate
AND f.qc_status = 'passed') AS 'Passed'
存储过程
USE [POCQC]
GO
/****** Object: StoredProcedure [dbo].[UrineCompliance] Script Date: 5/3/2018 3:18:09 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UrineCompliance] @Location AS NVARCHAR(50),
@StartDate AS DATE,
@EndDate AS DATE
AS
BEGIN
SELECT Count(DISTINCT CONVERT(VARCHAR, f.date_entered, 101)) AS 'Failed',
(SELECT Count(DISTINCT CONVERT(VARCHAR, f.date_entered, 101))
FROM de_urine f
WHERE f.location = @Location
AND f.date_entered BETWEEN @StartDate AND @EndDate
AND f.qc_status = 'passed') AS 'Passed'
FROM de_urine f
WHERE f.location = @Location
AND f.date_entered BETWEEN @StartDate AND @EndDate
AND f.qc_status = 'failed'
AND NOT EXISTS (SELECT *
FROM de_urine p
WHERE p.location = f.location
AND CONVERT(VARCHAR, p.date_entered, 101) =
CONVERT(VARCHAR, f.date_entered, 101)
AND p.qc_status = 'passed')
END