Is there a way to use this below top part, but not use any of the fields in the group by other than:a.Zip,a.clientid,a.state,a.agent?
By adding the other fields in the group by, it is messing up the results. But since those fields are in my case statements, it makes me use them in the group by line..Thanks..
(SELECT
/**************************/
case
when a.clientid ='9' then a.agency
else b.clientname
end as Client,
/**************************/
a.state,
a.agent as County,
a.Zip,
/**************************/
case
when a.status = 'initial call' then COUNT(a.Zip)
else '0'
end as PICMembers,
/**************************/
case
when a.status in ('member','pending scheduling','provider','reopen','scheduling','special handling') then COUNT(a.Zip)
else '0'
end as NYSMembers,
/**************************/
COUNT(a.Zip) as TotalMembers
FROM dbo.vwapp0 AS a WITH (nolock) INNER JOIN
dbo.vwaccount AS b WITH (nolock) ON a.clientID = b.ClientID
WHERE (a.StatusReason IN ('pending', 'reopen', 'reschedule', 'spanish pending', 'appointment issue')) AND (a.FuDt <= DATEADD(dd, 1, GETDATE()) OR
a.FuDt IS NULL)
GROUP BY a.Zip,a.clientid,a.state,a.agent,a.agency,b.clientname,a.status,a.state,a.agent,a.statusreason,a.status)
By adding the other fields in the group by, it is messing up the results. But since those fields are in my case statements, it makes me use them in the group by line..Thanks..
(SELECT
/**************************/
case
when a.clientid ='9' then a.agency
else b.clientname
end as Client,
/**************************/
a.state,
a.agent as County,
a.Zip,
/**************************/
case
when a.status = 'initial call' then COUNT(a.Zip)
else '0'
end as PICMembers,
/**************************/
case
when a.status in ('member','pending scheduling','provider','reopen','scheduling','special handling') then COUNT(a.Zip)
else '0'
end as NYSMembers,
/**************************/
COUNT(a.Zip) as TotalMembers
FROM dbo.vwapp0 AS a WITH (nolock) INNER JOIN
dbo.vwaccount AS b WITH (nolock) ON a.clientID = b.ClientID
WHERE (a.StatusReason IN ('pending', 'reopen', 'reschedule', 'spanish pending', 'appointment issue')) AND (a.FuDt <= DATEADD(dd, 1, GETDATE()) OR
a.FuDt IS NULL)
GROUP BY a.Zip,a.clientid,a.state,a.agent,a.agency,b.clientname,a.status,a.state,a.agent,a.statusreason,a.status)