Я довольно новичок в коде SQL и все еще учусь.
У меня есть таблица Gas_Data, в которой у меня есть количество дней, прошедших с определенного события DATEDIFF, мне нужно установить возрастной диапазон, и я изо всех сил пытаюсь написать требуемое кодирование.
Я попытался создать другую таблицу в качестве ссылки и попробовал различные варианты кодирования из примеров.
"Синтаксическая ошибка (отсутствует оператор) в выражении запроса 'CASE
UPDATE Gas_Data
SET MONTH_BAND =
CASE
WHEN DATEDIFF < 29 THEN '00. Up to 1 Month'
WHEN DATEDIFF BETWEEN 30 AND 60 THEN '01. 1 to 2 Months'
WHEN DATEDIFF BETWEEN 61 AND 60 THEN '02. 2 to 3 Months'
WHEN DATEDIFF BETWEEN 91 AND 60 THEN '03. 3 to 4 Months'
WHEN DATEDIFF BETWEEN 121 AND 60 THEN '04. 4 to 5 Months'
WHEN DATEDIFF BETWEEN 151 AND 60 THEN '05. 5 to 6 Months'
WHEN DATEDIFF BETWEEN 181 AND 60 THEN '06. 6 to 7 Months'
WHEN DATEDIFF BETWEEN 211 AND 60 THEN '07. 7 to 8 Months'
WHEN DATEDIFF BETWEEN 241 AND 60 THEN '08. 8 to 9 Months'
WHEN DATEDIFF BETWEEN 271 AND 60 THEN '09. 9 to 10 Months'
WHEN DATEDIFF BETWEEN 301 AND 60 THEN '10. 10 to 11 Months'
WHEN DATEDIFF BETWEEN 331 AND 60 THEN '11. 11 to 12 Months'
WHEN DATEDIFF BETWEEN 366 AND 60 THEN '12. 12 to 18 Months'
WHEN DATEDIFF BETWEEN 546 AND 60 THEN '13. 18 to 24 Months'
WHEN DATEDIFF BETWEEN 731 AND 60 THEN '14. 24 to 30 Months'
WHEN DATEDIFF BETWEEN 911 AND 60 THEN '15. 30 to 36 Months'
WHEN DATEDIFF >= 1096 THEN '16. > 36 Months'
ELSE 'NO_AGE_BAND' END AS UNBILLED_MONTHS
END
MONTH_BAND
00. Up to 1 Month
01. 1 to 2 Months
02. 2 to 3 Months
03. 3 to 4 Months
04. 4 to 5 Months
05. 5 to 6 Months
06. 6 to 7 Months
07. 7 to 8 Months
08. 8 to 9 Months
09. 9 to 10 Months
11. 11 to 12 Months
12. 12 to 18 Months
13. 18 to 24 Months
14. 24 to 30 Months
15. 30 to 36 Months
16. > 36 Months