How to perform an "IF" by SQL

1

Hello, how can I do something similar to an if but per sql? For example: There is a field in the database named dt_ini with no value so far. I would like to do: "If dt_ini == '' insert into table ( dt_ini ) values ..."
I would have to query the database to see the dt_ini is or has the null value, if yes insert into ... else ...

    
asked by anonymous 04.10.2017 / 19:42

2 answers

-1

Oops MrVanDaime, try the following,

OR

INSERT INTO YOUR_TABELA (dt_ini) VALUES VALUE WHERE DT_INI =     

04.10.2017 / 21:29
-1

Let me see if I understand, you want to update the value of the dt_ini of the table itself? if it is empty?

If so, try this:

UPDATE SUA_TABELA SET DT_INI = VALOR WHERE DT_INI IS NULL

If it is an insert elsewhere, if dt_ini is empty, try:

INSERT INTO SUA_TABELA (CAMPOS) VALUES (VALORES) WHERE 1 IN (SELECT 1 FROM SUA_TABELA WHERE DT_INI IS NULL)
    
04.10.2017 / 22:57