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
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Thanks for the split.  Good luck with your project.  -Jim
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo