my query:
SELECT
CASE
WHEN
DAYS(DATE(
SUBSTR(DIGITS(STOCK_MONTH),5,4) CONCAT '-' CONCAT
SUBSTR(DIGITS(STOCK_MONTH),9,2) CONCAT '-01') - 1 DAY + 1 MONTH)
- DAYS(HUB_ARRIVAL_DT) < 31 THEN ' 030'
WHEN
DAYS(DATE(
SUBSTR(DIGITS(STOCK_MONTH),5,4) CONCAT '-' CONCAT
SUBSTR(DIGITS(STOCK_MONTH),9,2) CONCAT '-01') - 1 DAY + 1 MONTH)
- DAYS(HUB_ARRIVAL_DT) < 61 THEN ' 060'
WHEN
DAYS(DATE(
SUBSTR(DIGITS(STOCK_MONTH),5,4) CONCAT '-' CONCAT
SUBSTR(DIGITS(STOCK_MONTH),9,2) CONCAT '-01') - 1 DAY + 1 MONTH)
- DAYS(HUB_ARRIVAL_DT) < 91 THEN ' 090'
WHEN
DAYS(DATE(
SUBSTR(DIGITS(STOCK_MONTH),5,4) CONCAT '-' CONCAT
SUBSTR(DIGITS(STOCK_MONTH),9,2) CONCAT '-01') - 1 DAY + 1 MONTH)
- DAYS(HUB_ARRIVAL_DT) < 181 THEN ' 180'
ELSE '>180'
END AS AGED
FROM ...
you can see the following parts is copied several times
DAYS(DATE(
SUBSTR(DIGITS(STOCK_MONTH),5,4) CONCAT '-' CONCAT
SUBSTR(DIGITS(STOCK_MONTH),9,2) CONCAT '-01') - 1 DAY + 1 MONTH)
- DAYS(HUB_ARRIVAL_DT)
Is it possible to have this only once? If so, how? Will this have a performance impact? Thanks! Database is DB2.