i learned a lot in the past month and that forum helps me a lot,
but now i stuck on the below case and can't understand why this was written.
Maybe you can give me a hind to understand that code.
CASE WHEN b.globl_rgn_cd IN ('US','EU','CA','LAC') AND y.current_dt IN ('2010-01-01') THEN y.hour_diff1 - 12
WHEN b.globl_rgn_cd IN ('US') AND y.current_dt IN ('2010-07-05') THEN y.hour_diff1 - 36
WHEN b.globl_rgn_cd IN ('US','EU','CA','LAC') AND y.current_dt IN ('2010-01-04') THEN y.hour_diff1 - 36
ELSE y.hour_diff1 END AS hour_diff,
Thank you very much in advance.
The "Why" this was written was to execute a business rule, but the deeper why - that is "why this specific business rule" can never be understood just from this code. You would need to speak to a subject matter expert and/or the person who actually wrote the code.
In the code there are 3 conditions under which the field y.hour_diff1 will be modified. All 3 conditions look at what I assume is a region code in combination with the current date. The date comparison uses an IN operator, but could just as easily used the = sign. One of the combinations, subtracts 12 from y.hour_diff1 and the other two combinations subtract 36 from y.hour_diff1. Since we don't know what y.hour_diff1 is, we don't really know the units for 12 or 36. If none of those 3 conditions are met, then the expression returns y.hour_diff1 without being modified and names it, hour_diff .
The region code comes from object b and hour_diff1 comes from object y, so there must be a join somewhere in the query from which this was pulled.
So that's as much as you can know about this code snippet without understanding what hour_diff1 actually represents. You might find that in other parts of the query or you're simply going to have to find the author.