Need some help with TSQL Case Statement.

Posted on 2012-09-17
Last Modified: 2012-09-17
Current Statement

select emp.fullname,emp.dept,emp.deptLstnon9800 from ol_employee emp
where 'A'='A'
AND  (case emp.dept when '9800' then deptlstnon9800 else EMP.dept end  Not like  '45%')
AND  (case emp.dept when '9800' then deptlstnon9800 else EMP.dept end  Not like  '46%')
order by dept

Currently it just looks at emp.dep when '9800'.  I now need to also add  '4800' to the WHEN.  

Thought I coud just use "OR" or IN but neither work I get errors.  Looking for some assistance on how to do this.

Question by:Rog
    LVL 15

    Accepted Solution

    CASE WHEN emp.dept = '9800' OR emp.dept = '4800' THEN deptlstnon9800 ELSE emp.dept END
    LVL 8

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now