Sql Connector - Write NULL intead of empty in SQL Database

Hello dear Bubble fan :slight_smile:

I have a small question regarding SQL.
I am writing data to an MS Sql Database with the plugin SQL Database Connector.
It’s working fine. But when I have a input value is not filled, then the information stored on the database is empty, and I would like to keep it as NULL.

I tried to manage it in the SQL command and add a test IF @variable IS β€˜β€™ then @variable = NULL
which is working for one or two line, but not possible for all of field.
If I add the test more than 10 times, it create an sql ECONNRESET error.

Any solution or work around?
If possible maybe not a State, since I have more than 30 field to fill in the database.

Thanks in advance for your help and for taking the time to read me.

@damien.heritier use an input as middle man to where you are passing this value. And you can set the condition of value is β€œβ€ content of the input is Null. And you pass this to the MS Sql Database.

Thanks for your message, but still the same behavior.
The value return from the input is (empty) but on the database, the result is β€˜β€™ and not NULL.

Would Nullif(@variable’’) not work for your situation?

Can you give some more specifics around what you are trying to achieve with the IF THEN. Are you inserting or updating records?

You could do something like this:
IF COALESCE(@SomeVarcharParm, '') = '' BEGIN [Do Something Here] END

Alternatively you could write the check directly into a query insert/update but it is a bit difficult to offer an exact solution without understanding what you are trying to accomplish with the IF THEN. To be clear in SQL Server you must specify the record as null in your insert/updates or sql server as that is a special value.


Sorry for the late reply.

I solved my issues by splitting the SQL command in 2 commands to avoid the ECONNRESET error.

IF @test = β€˜β€™ SET @test= NULL ; …
---- Update
UPDATE Database
SET test= @test, …

I was thinking that I could define Null before the SQL command, but the test IF SET seems to be the best solution.
Just my sql command was too long (too many field to fill)