Files
erv-clientright/n8n_policy_check_sql_with_data.sql
2026-03-13 10:42:01 +03:00

37 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Расширенный вариант: возвращает все данные полиса + флаги валидности
-- Аналогичен основному запросу, но с дополнительными флагами для детальной проверки
SELECT
*,
-- Флаг валидности тарифа
CASE
WHEN tariff_code_basic IN ('STB0048', 'STB1099', 'STB1100', 'STB2099', 'AVS21500', 'AVS22500')
OR tariff_code_other IN (
'SPV0001', 'SPV0002', 'SPV0003', 'SPV0004', 'SPV0005',
'STV0090',
'SPV1001', 'SPV1002', 'SPV1003', 'SPV1004', 'SPV1005',
'SPV2001', 'SPV2002', 'SPV2004', 'SPV2005',
'OPV1001', 'OPV1002', 'OPV1003', 'OPV1004', 'OPV1005',
'OPV2001', 'OPV2002', 'OPV2004', 'OPV2005'
)
THEN 1
ELSE 0
END AS is_valid_tariff,
-- Общий флаг: найден и валиден (основной для IF Node)
CASE
WHEN tariff_code_basic IN ('STB0048', 'STB1099', 'STB1100', 'STB2099', 'AVS21500', 'AVS22500')
OR tariff_code_other IN (
'SPV0001', 'SPV0002', 'SPV0003', 'SPV0004', 'SPV0005',
'STV0090',
'SPV1001', 'SPV1002', 'SPV1003', 'SPV1004', 'SPV1005',
'SPV2001', 'SPV2002', 'SPV2004', 'SPV2005',
'OPV1001', 'OPV1002', 'OPV1003', 'OPV1004', 'OPV1005',
'OPV2001', 'OPV2002', 'OPV2004', 'OPV2005'
)
THEN 1
ELSE 0
END AS found
FROM lexrpiority
WHERE voucher = :voucher
LIMIT 1;