troubleshooting Question

Help getting correct SQL syntax for a "crosstab query" report in SQL Server

Avatar of britpopfan74
britpopfan74Flag for United States of America asked on
Microsoft SQL Server
4 Comments1 Solution346 ViewsLast Modified:
Hello,

The purpose of the report I'm trying to create is to find out if a member is being brought
back to a clinic several times (separate DOS) to have multiple procedures performed.

Each of the 6 procedures (LINE_CODE) listed in my basic code below HAS THE POSSIBILITY OF BEING DONE ON BOTH THE RT AND LT SIDES OF THE BODY, so essentially, I'd like to show every possible combination (12 procedures) for any given member, even if he isn't having all performed.

I think to show this data most effectively to the provider will be to show a format similar to as follows:


MEMBER      DOS      PROC1_RT DONE  PROC1_LT NOT DONE (checks) ...PROC12_LT... PAID AMT/DOS
 A      1/5/11       1               0                            0            $1000
 A      1/12/11      0               1                            0            $500
 A      1/12/11           1               0                            0                          $200


Then later I can do summary statistics on the counts per member (make sure procedures aren't being duplicated unnecessarily) and average costs per procedure...

Anyhow, any advice is much appreciated; thank you


Current coding - gets all members having these procedures:

SELECT DISTINCT MC.MEMBER
, MC.FIRST_DOS
, CASE WHEN MCD.LINE_CODE IN('36478','36479') THEN 'LASER'
         WHEN MCD.LINE_CODE IN('36470','36471') THEN 'UGS'
       WHEN MCD.LINE_CODE IN('36011','37204') THEN 'TCC'
      END AS TX
, MCD.MOD1
, MCD.MOD2
, MC.TOTAL_PAY_AMT
INTO #MC_STATUS
FROM #temp_CLAIMS_MC MC
INNER JOIN MASTER_CLAIM#DETAIL mcd ON mc.[DOCUMENT] = mcd.[DOCUMENT]
WHERE (MCD.LINE_CODE IN('36478','36479','36470','36471','36011','37204') )
AND
((MCD.MOD1 IN('RT','LT'))
OR (MCD.MOD2 IN('RT','LT')))
ORDER BY MC.MEMBER, MCD.LINE_CODE, MCD.MOD1, MCD.MOD2, FIRST_DOS

--counting the distinct procedures:

SELECT MEMBER
, FIRST_DOS
, COUNT(DISTINCT PROCD) AS COUNT_DISTINCT_PROCS
FROM #MC_STATUS
GROUP BY MEMBER
ORDER BY COUNT(DISTINCT PROCD) DESC
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros