I have a sql query where SQL Server outputs data to looks like this
| ScheduledAppts | KeptAppts | UnkeptAppts |
|---|---|---|
| 30 | 20 | 10 |
And I want to alter this output into a sql server #temp table so it looks like this:
| Category | Count |
|---|---|
| ScheduledAppts | 30 |
| KeptAppts | 20 |
| UnkeptAppts | 10 |
Been trying to use Pivot but I think I'm doing it wrong.
Code:
SELECT
COUNT(x.Scheduled) AS ScheduledAppts,
COUNT(x.KeptEncounters) AS KeptAppts,
COUNT(x.UnkeptEncounters) AS UnkeptAppts
FROM (
SELECT DISTINCT
COUNT(frz.TotalAppt) AS Scheduled,
CASE
WHEN frz.PDEncounters > 0 THEN
COUNT(frz.PDEncounters)
END AS KeptEncounters,
CASE
WHEN frz.PDEncounters = 0 THEN
COUNT(frz.PDEncounters)
END AS UnkeptEncounters,
FROM [CDW].[dbo].[Fact_FREEZEPOLICE] frz
) x