PDA

Click to See Complete Forum and Search --> : case statement with sql!!!


Bebe
Jun 22nd, 2000, 09:07 AM
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)

Mongo
Jun 23rd, 2000, 02:09 AM
Something along these lines may help...

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