Completed Appointments by Provider (for date range)

For complex topics that regular users would not be interested in. For power users and database administrators.
Post Reply
V Suite
Posts: 136
Joined: Sun Aug 19, 2007 6:56 pm

Completed Appointments by Provider (for date range)

Post by V Suite » Wed Dec 23, 2009 5:13 pm

Based on Query # 142, which gives the total number of appointments in a given range, the following query separates tabulates the appointments by provider.

Code: Select all

SET @FromDate='2009-12-01' , @ToDate='2009-12-31';
SELECT ProvNum, (SELECT Count(*) FROM appointment WHERE aptstatus=2 AND ProvNum=provider.ProvNum AND AptDateTime BETWEEN @FromDate AND @ToDate) AS '#Appointments' FROM provider
Now if only there was a way to make a query to tabulate by month horizontally and provider vertically.

V Suite
Posts: 136
Joined: Sun Aug 19, 2007 6:56 pm

Re: Completed Appointments by Provider (for date range)

Post by V Suite » Thu Dec 24, 2009 9:51 pm

Sorry, this does not work if FromDate = ToDate. To fix, use

Code: Select all

SET @FromDate='2009-12-01' , @ToDate='2009-12-31';
SELECT ProvNum, (SELECT Count(*) FROM appointment WHERE aptstatus=2 AND ProvNum=provider.ProvNum AND DATE(AptDateTime) BETWEEN @FromDate AND @ToDate) AS '#Appointments' FROM provider
Cheers

Post Reply