Results 1 to 2 of 2

Thread: case statement with sql!!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    is there a way to do this with a case statement?


    update #totals
    set cutoff = '3:00pm'
    where id in (14,15)

    update #totals
    set cutoff = '1:00pm'
    where id in (16)

    update #totals
    set cutoff = '12:00pm'
    where id in (17,18,19,20)

    update #totals
    set cutoff = '9:00am'
    where id in (21)

    update #totals
    set cutoff = '2:40pm'
    where id in (22)

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Something along these lines may help...
    Code:
    CREATE VIEW v_NLT (id, cutofftm) AS 
      SELECT id, 
        CASE 
          WHEN id > 13 AND id < 16 THEN '3:00pm'
          WHEN id = 16 THEN '1:00pm'
          WHEN id > 16 AND id < 21 THEN '12:00pm' 
          WHEN id = 21 THEN '9:00am' 
          WHEN id = 22 THEN '2:40pm' 
          ELSE 'u/i'
        END
      FROM #totals 
      GROUP BY id;
    
    UPDATE #totals 
      SET t.cutoff = v.cutofftm
      FROM #totals AS t, v_NLT AS v
      WHERE t.id = v.id

Posting Permissions

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



Click Here to Expand Forum to Full Width