Hi,
I need to calculate average response times in days (from the date a letter is posted to when a reply is received). I use the following to get the total days difference, and when output to Excel with the count of letters sent it works just fine.
DECLARE @DAYDIFF INT
SET @DAYDIFF = (SELECT SUM(DATEDIFF(day, kf.ReplyReceived, kf.InstructionSent))
FROM Reports1.dbo.KeyFields kf
WHERE Canx2 IS NULL)
My problem is that I need to also calculate (again within Excel) what percentage of the letters were over 14 days between send & receive. So I need to use COUNT to give me the number over 14 days DATEDIFF. I have tried the following (but it isn't right, and I am struggling to fix it) :
DECLARE @DAYDIFF INT
DECLARE @COUNTGT14 INT
SET @COUNTGT14 = (SELECT (COUNT @DAYDIFF = DATEDIFF(day, kf.ReplyReceived, kf.InstructionSent)
FROM Reports1.dbo.KeyFields kf
WHERE Canx2 IS NULL
AND @DAYDIFF > 14)
Suggestions would be appreciated.
Thanks,
Paul
I need to calculate average response times in days (from the date a letter is posted to when a reply is received). I use the following to get the total days difference, and when output to Excel with the count of letters sent it works just fine.
DECLARE @DAYDIFF INT
SET @DAYDIFF = (SELECT SUM(DATEDIFF(day, kf.ReplyReceived, kf.InstructionSent))
FROM Reports1.dbo.KeyFields kf
WHERE Canx2 IS NULL)
My problem is that I need to also calculate (again within Excel) what percentage of the letters were over 14 days between send & receive. So I need to use COUNT to give me the number over 14 days DATEDIFF. I have tried the following (but it isn't right, and I am struggling to fix it) :
DECLARE @DAYDIFF INT
DECLARE @COUNTGT14 INT
SET @COUNTGT14 = (SELECT (COUNT @DAYDIFF = DATEDIFF(day, kf.ReplyReceived, kf.InstructionSent)
FROM Reports1.dbo.KeyFields kf
WHERE Canx2 IS NULL
AND @DAYDIFF > 14)
Suggestions would be appreciated.
Thanks,
Paul