Burco Burco - 2 months ago 6
SQL Question

SQL select if value higher save as column1, else save as column2

Is it possible to do something like this:

IF datalength(U_Partner) > 5 THEN save value '9999' into room_id and U_Partner value into partners_id
IF datalength(U_Partner) <= 4 THEN save value U_Partner into room_id and '9999'
value into partners_id

CASE WHEN datalength T5.U_Partner > 5 THEN '9999' ELSE T5.U_Partner END as room_id,


I have this, but I don't know how to add second save. Is it even possible.

Answer

You could use two Case in this scenario. each Case for each column. The code would be something like this:

Select
CASE WHEN datalength(T5.U_Partner) > 5 THEN '9999' ELSE T5.U_Partner END as room_id,
CASE WHEN datalength(T5.U_Partner) > 5 THEN T5.U_Partner ELSE '9999' END as partners_id