Results 1 to 3 of 3

Thread: CASE statement

  1. #1
    Join Date
    Jan 2004
    Posts
    2

    Unanswered: CASE statement

    I am trying to write a case statement that will look at a relationship between two fields. I have done this in the past but not one that needs to look at various options in one of the fields.

    Example. I am comparing a location code to a code where an employee's check is mailed.

    CASE
    WHEN EjLocation ='AGACES'
    THEN '3410'


    But I need to also include 3415 and any check code that begins with 83 (i.e. 8315, 8350). How do I include this in the THEN statement?

    Thanks!

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Could you post a small sample set and the result set you would like to see?

  3. #3
    Join Date
    Jan 2004
    Posts
    2
    Originally posted by Teddy
    Could you post a small sample set and the result set you would like to see?
    Here is the query that I have started. Just need to work on the CASE statement.
    My goal is to just show employees whose EjLocation doesn't match the PrbCheckSeqNo listed in the THEN statement.

    IE
    Name Location CheckCode
    John Smith AGACES 8500

    This person would show up because they don't equal 3410, 3415 or a code starting with 83##.

    SELECT EpLastName, EpFirstName, EjLocation, PrbCheckSeqNo
    FROM EJob, EBase, EPayrollBase
    /* Check codes not matching facility code- excludes virtuals
    Dev. T.Rucker 1/04 */
    WHERE EpFlxideb = EjFlxideb AND Ebflxid = Prbflxideb AND PrbDateend is null AND EjDateEnd IS NULL AND Epflxideb = EeFlxideb AND
    EeDateEnd IS NULL AND NOT PrbCheckSeqNo = '0000' AND
    CASE
    WHEN EjLocation ='AGACES'
    THEN '3410'
    WHEN EjLocation = 'BALCES'
    THEN '2300'
    ELSE 'O'
    END <> PrbCheckSeqNo
    ORDER BY EjLocation, PrbCheckSeqNo

Posting Permissions

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