08-10-2005 11:00 AM
08-11-2005 07:26 PM
08-15-2005 09:53 AM
Hello Phillip,
Your answer explains what (and why) happens if I pass an 'empty' parameter value.
However that does not fully answer my question, which I have rephrased below:
I want to know how to pass NULL values because if I do that, I can continue to use parameterised query (something which I HAVE to do since SQL query cannot handle the said tasks). In VB, saying NULL (and not 'NULL') tells the compiler that it has to pass null values and not the word null - and this works for parameterised query too. I want to know if LV has something similar.
Hope I have been able to clearly state my question.
Thanks,
Gurdas
08-17-2005 12:00 AM
08-17-2005 04:48 AM
Can you store NULL-values in that specific column?
Than you should change your query, so that column is not mentiod
e.g
Your table1: col1, col2 and col3
col3 can store null-values
If you want to insert null in col3 insert:
insert into table1(col1, col2)
values(?, ?)
08-17-2005 11:22 AM
Maximus,
The said columns have 'can be null' activated in SQL server design table page.
However, the column will at some occassions have non-null values. There are 5 such columns. Each stores char data type and each can be null or non-null. The problem is NOT when I am first inserting the recordset. If the string control is 'empty' the field is set to null in the database. If the string control has a string, it goes into the target field. So far so good.
The problem occurs when I am trying to update a existing recordset. Here I use a stored procedure and paramterised query. Now, if any of the 5 string controls is passing a empty (aka null), an error is reported and the complete row (which has other columns) is not updated. Very irritating.
There are two possible workarounds (we chose the first):
1) Force the user to type some string in the control
2) Check for empty and if true substitute it with a white space.
If only LV had a null equivalent ....
Thanks,
Gurdas
08-18-2005 02:08 AM
In the case of the stored procedure it is easy:
You just need to set the default value of the parameter to NULL:
CREATE PROCEDURE [update_MyTable]
(@fldID numeric,
@fldData real,
@fldText varchar(50)= NULL)
as
UPDATE MyTable
SETfldData = @fldData,
fldText = @fldText
WHERE ( fldIDs = @fldID)
Through the "@fldText varchar(50)= NULL)" a default value will be used if that parameter is not specified (in this case, null is used)
10-23-2008 07:42 AM - edited 10-23-2008 07:43 AM
First of all set the default_value of the parameter to an empty string in Parameter in of DB Tools Create Parameterized Query.vi
After that check if the string control is empty or not (case) if it's empty don't use DB Tools Set Parameter Value.vi, if the string has some value not null use the DB Tools Set Parameter Value.vi to set the value.
This works to set null values to stored procedures (tested with Oracle).
See null.jpg example attached.
06-12-2009 09:27 AM
I can't say for other databases, but for SQL Server, I found a neat way to send a NULL value to our database that works with parameterized queries. Drop a Database to Variant vi on your diagram. Right-click the output and create a CONSTANT. Don't put anything in it. Wire it in where you want to send a NULL. Lose the Database to Variant vi. Works a treat.
Tay
06-18-2013 12:20 PM
I had given this a kudo to the empty variant idea, but then I checked if it worked. The parameterized query will run, but the data in the DB table is not a NULL. It is the default datatype for the field.