Hello Folks,
I am stuck and am going nowhere.
I have two tables
MinuteCategory
------------------
Minute
MinuteCategory
MinuteLookup
--------------------
MinuteCategoryId (surrogate key)
MinuteLow
MinuteHigh
MinuteCategory
Sample from Minute Lookup table ..
11
15<15 min
216
30<30 min
331
45<45 min
446
60<60 minutes
561
75<1 hour 15 minutes
.
.
.
.
.. . . . .
I am trying to update the MinuteCategory column in the MinuteCategory table using the MinuteLookup table.
For example if the minute = 33 then the corresponding lookup value would be 3 (from the lookup table), because the
33rd minute falls in between 31 min and 45 min and the corresponding surrogate key is 3
Is this possible with an Update statement in SQL? The only thing i can think of is use case statement as the join key between
the two tables but i don't think it's going to work :(
UPDATE
SET MinuteCategory = ml.MinuteCategoryId
FROM MinuteCategory mc join MinuteLookup ml on mc.Minute =
CASE WHEN mc.Minute between ml.MinuteLow and ml.MinuteHigh THEN ml.MinuteCategoryId ELSE NULL
END
Would appreciate any help.
SS