Page 1 of 1

Case used in SQL Query Any Sugestios?

Posted: 2023-07-22 08:06
by fanton
Field VarChar= `Reg_Determinari`.`RH_D - OPTION LIST (Pozitiv;;Negativ;;Incert;;_______;;D Slab)
Field VarChar= `Reg_Determinari`.`D`

Query:

SELECT `Reg_Determinari`.`RH_D`, `Reg_Determinari`.`D`
CASE
WHEN`Reg_Determinari`.`RH_D` = 'Pozitiv' THEN 'D'
WHEN`Reg_Determinari`.`RH_D` = 'Negativ' THEN 'd'
WHEN`Reg_Determinari`.`RH_D` = 'Incert' THEN 'D(incert)'
WHEN`Reg_Determinari`.`RH_D` = 'D Slab' THEN 'D(Slab)'
WHEN`Reg_Determinari`.`RH_D` = '_______' THEN ''
END AS `Reg_Determinari`.`D`

FROM `Reg_Determinari`
WHERE `Reg_Determinari`.`ID`='%ID%'

Re: Case used in SQL Query Any Sugestios?

Posted: 2023-07-31 07:03
by onoehring
Hi,

aha, and what is your question, problem, desired result?
Maybe this helps: https://www.mysqltutorial.org/mysql-case-function/ and https://www.w3schools.com/SQL/func_mysql_case.asp

Olaf

Re: Case used in SQL Query Any Sugestios?

Posted: 2023-07-31 10:46
by jsetzer
I agree with Olaf: your question is not very clear. I guess you have problems with SQL for a calculated field, right?

SQL query for calculated field should return exactly one value.

Code: Select all

SELECT CASE
WHEN`Reg_Determinari`.`RH_D` = 'Pozitiv' THEN 'D'
WHEN`Reg_Determinari`.`RH_D` = 'Negativ' THEN 'd'
WHEN`Reg_Determinari`.`RH_D` = 'Incert' THEN 'D(incert)'
WHEN`Reg_Determinari`.`RH_D` = 'D Slab' THEN 'D(Slab)'
WHEN`Reg_Determinari`.`RH_D` = '_______' THEN ''
END FROM `Reg_Determinari`
WHERE `Reg_Determinari`.`ID`='%ID%'
PS: please always put code in [code]...[/code]-tags for better readability.