+ Reply to Thread
Results 1 to 2 of 2

Thread: Using CASE

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    10

    Using CASE

    I have a problem with that code :
    Code:
    select email, user_id, first_name, last_name, rights
    from users u
    where company_id = 2141
        and receives_emails = 'y'
        case u.rights when 'manager' then
            and user_id in (select user_id from manager_depts where company_id = u.company_id and dept_id = 2)
        end
    Could you please help me correct it ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    41
    You actually do not need a CASE here,
    Code:
    SELECT email, u.user_id, first_name, last_name, rights
    FROM users u
         LEFT JOIN manager_depts d ON d.company_id = u.company_id and d.dept_id = 2
    WHERE company_id = 2141 AND receives_emails = 'y'
      AND (u.rights != 'manager' OR d.user_id IS NOT NULL)

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts