troubleshooting Question

Why am I getting an error with this SELECT statement?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
Microsoft SQL Server
5 Comments1 Solution109 ViewsLast Modified:
Here's my SELECT query:

 select a.* from
         select b.encountercode, patient.patientid, practicepatientid, practiceaccountid, client.clientcode, practice.practicecode, practicename, patientfname, patientlname, patientdob, dbo.ufn_getSSN(patient.accountid) as patientssn, patientgender, patient.accountid, accountstatuscode, accountstatuscode2, patientadminstatuscode, patientfinancialstatuscode 

        , ( (case when account.practiceaccountid like ('%Johnson%') then 1 else 0 end)  +  (case when patient.patientlname like ('%Johnson%') then 1 else 0 end)  +  (case when patient.patientfname like ('%Johnson%') then 1 else 0 end)  +  (case when account.accountid like ('%Johnson%') then 1 else 0 end)  +  (case when b.encountercode like ('%Johnson%') then 1 else 0 end) ) as hits from 
        account (nolock)
            join patient (nolock) on patient.accountid = account.accountid
            join practice (nolock) on account.practiceid = practice.PracticeID
            join client (nolock) on practice.clientid = client.clientid
			LEFT JOIN (SELECT TOP 1 ChargeGroup.AccountID, ChargeGroup.encountercode FROM ChargeGroup (nolock) 
			ChargeGroup.clientcode='AIRCARE') b 
			ON Account.AccountID=b.AccountID
        where client.clientcode in('AIRCARE','ALLEN','AMG','BCMH','BBGH','CMI','DALE','DHDC','DCC','DMH','ECH','FCH','GAH','DEMO','HRMC','DSCHD','DSCHD2','HOUCOHO','LMCH','MCGH','SDP','MERCY','OVSH','PF','PCMG','RCC','SMC','SMH','TONC','TRAD','TPS','TTT','00077793111','UGH','URMC','UTH','UTS','CPAP','CPAPNew','WCH','WMC')
        ) a
    where hits > 0
    order by  hits desc, patientlname asc 

When it runs, I get this error:

Msg 102, Level 15, State 1, Line 14
Incorrect syntax near ','.

Line 14 being: ChargeGroup.clientcode='AIRCARE','ALLEN','AMG','BCMH','BBGH','CMI','DALE',
                  'TPS','TTT','00077793111','UGH','URMC','UTH','UTS','CPAP','CPAPNew','WCH','WMC') b

When I run it as ChargeGroup.clientcode='AIRCARE') b - no problem. There appears to be something flawed in the way I'm running it with more than one option, but I don't know how to fix it.

Kent Olsen
Data Warehouse / Database Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 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 5 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