Avatar of shelbyinfotech
shelbyinfotech
 asked on

Syntax error using CASE...WHEN

Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '='.



SELECT RTRIM(LTRIM(CLASTNAME)) + ' , ' + RTRIM(LTRIM(CFIRSTNAME)) AS EMPNAME,
       CGROUP2                                                    AS EMPDEPT,
       CEMPID                                                     AS EMPID,
       CGROUP1,
       DEPTCODE = CASE UPPER(RTRIM(LTRIM([CGROUP2])))
                    WHEN UPPER(RTRIM(LTRIM([CGROUP2]))) = 'COMMERCIAL PERMITS'
                  THEN
                    'COM'
                    WHEN UPPER(RTRIM(LTRIM([CGROUP2]))) = 'COMMERCIAL REAPPRAIS'
                  THEN
                    'COM'
                    WHEN UPPER(RTRIM(LTRIM([CGROUP2]))) = 'RESIDENTIAL PERMITS'
                  THEN
                    'RES'
                    WHEN UPPER(RTRIM(LTRIM([CGROUP2]))) = 'RESIDENTIAL REAPPRAI'
                  THEN
                    'RES'
                    ELSE 'OTH'
                  END
FROM   EMPLOYEE
WHERE  ( RIGHT('000' + RTRIM(LTRIM(CEMPID)), 5) = '10515' )  

Open in new window

Microsoft SQL ServerMicrosoft SQL Server 2005SQL

Avatar of undefined
Last Comment
Jim Horn

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sean Stuber

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Jim Horn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jim Horn

Thanks for the split.  Good luck with your project.  -Jim
Your help has saved me hundreds of hours of internet surfing.
fblack61