troubleshooting Question

Syntax error using CASE...WHEN

Avatar of shelbyinfotech
shelbyinfotech asked on
Microsoft SQL ServerMicrosoft SQL Server 2005SQL
3 Comments2 Solutions473 ViewsLast Modified:
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' )  
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 3 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 2 Answers and 3 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