CASE es una función compleja que tiene dos formatos: el formato when-sencillo y el formato when-buscado. En cualquiera de ambos formatos, CASE devuelve un valor, cuyo resultado controla la vía de acceso del proceso posterior.
Ambos formatos de CASE devuelven un valor que depende de un conjunto de normas definidas en cláusulas WHEN.
En el formato when-sencillo, el valor_origen se compara con cada valor_prueba hasta que se encuentra una coincidencia. El resultado de la función CASE es el valor del valor_resultado correspondiente. El tipo de datos de valor_origen, por consiguiente, debe ser comparable al tipo de datos de cada valor_prueba.
La función CASE debe tener una cláusula WHEN como mínimo. ELSE es opcional. La expresión ELSE por omisión es NULL. Una expresión CASE se delimita con END. No es necesario que los valores de prueba sean valores literales.
La versión de la cláusula when-buscado es similar, pero tiene la flexibilidad adicional de permitir que se prueben varios valores diferentes.
DECLARE CurrentMonth CHAR; DECLARE MonthText CHAR; SET CurrentMonth = SUBSTRING(InputBody.Invoice.InvoiceDate FROM 6 FOR 2); SET MonthText = CASE CurrentMonth WHEN '01' THEN 'January' WHEN '02' THEN 'February' WHEN '03' THEN 'March' WHEN '04' THEN 'April' WHEN '05' THEN 'May' WHEN '06' THEN 'June' ELSE 'Second half of year' END
DECLARE CurrentMonth CHAR; DECLARE MonthText CHAR; SET CurrentMonth = SUBSTRING(InputBody.Invoice.InvoiceDate FROM 6 FOR 2); SET MonthText = CASE WHEN Month = '01' THEN 'January' WHEN Month = '02' THEN 'February' WHEN Month = '03' THEN 'March' WHEN Month = '04' THEN 'April' WHEN Month = '05' THEN 'May' WHEN Month = '06' THEN 'June' ELSE 'Second half of year' END
DECLARE CurrentMonth CHAR; DECLARE CurrentYear CHAR; DECLARE MonthText CHAR; SET CurrentMonth = SUBSTRING(InputBody.Invoice.InvoiceDate FROM 6 FOR 2); SET CurrentYear = SUBSTRING(InputBody.Invoice.InvoiceDate FROM 1 FOR 4); SET MonthText = CASE WHEN CurrentMonth = '01' THEN 'January' WHEN CurrentMonth = '02' THEN 'February' WHEN CurrentMonth = '03' THEN 'March' WHEN CurrentYear = '2000' THEN 'A month in the Year 2000' WHEN CurrentYear = '2001' THEN 'A month in the Year 2001' ELSE 'Not first three months of any year or a month in the Year 2000 or 2001' END;
Conceptos relacionados
ESQL
Tareas relacionadas
Desarrollo de ESQL
Referencia relacionada
Preferencia de sintaxis
Funciones ESQL complejas
Sentencia MOVE
Avisos |
Marcas registradas |
Descargas |
Biblioteca |
Soporte |
Información de retorno (feedback)
![]() ![]() |
ak05600_ |