Created
May 2, 2017 22:15
-
-
Save dperussina/379bc9b94d0d69fadf3273a0e4ec20f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT a.serviceproviderid, | |
Sum(CASE | |
WHEN b.notecode = 'RE' THEN 1 | |
ELSE 0 | |
END) AS RECount, | |
Sum (CASE | |
WHEN a.lastupdate >= Dateadd(day, -2 + CASE Datediff(day, 0, | |
Getdate()) % | |
7 | |
WHEN 0 THEN 1 | |
WHEN 5 THEN 2 | |
WHEN 6 THEN 1 | |
ELSE 0 | |
END, Getdate()) THEN 1 | |
ELSE 0 | |
END) AS InboundTest | |
FROM tagnet_appointmentspn_orders a | |
LEFT JOIN [dbo].[tagnet_appointmentspn_partnerordernotes] b | |
ON a.[partnerprimaryorderid] = b.[partnerprimaryorderid] | |
WHERE orderstate = 36 | |
GROUP BY a.serviceproviderid | |
ORDER BY a.serviceproviderid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment