LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL query for empty string

Solved!
Go to solution

I am trying to execute the following SQl query, SELECT * FROM Failure WHERE ID = '123' AND RepairAction = ' ';, using the DB Tools Execute Query.vi. This query never finds the record in my database. My database contains a record where the ID filed contains the value of '123' and the RepairAction field is an empty string. If I remove the 'AND RepairAction ' ';' text from my query statement, the record is found. I believe my problem is that I am not using the correct syntax to describe and empty string. I have tried the following: '', ' ', "", " ", and NULL as empty string arguments, and none of these work.

I was hoping someone might be able to tell me what the correct syntax is for an empty string or if there is another approach I need to take.

Thank you in advance for your help,

Jim

0 Kudos
Message 1 of 9
(23,195 Views)

Hi,

 

While creating your table "Failure", was the column "ID" delclared as intiger or varchar? If it is intiger and you use '123' , it wont return the results. You will have to try without the inverted comas ' '.

 

Regards,


Nitzz

(Giver Kudos to good Answers, Mark it as a solution if your problem is Solved;))

0 Kudos
Message 2 of 9
(23,190 Views)

Hi there Jim,

 

you could try modifying your command just a little bit. Try this:

 

...AND RepairAction is null;

 

It works for me in Oracle.

 

Cheers,

 

Cerati

0 Kudos
Message 3 of 9
(23,119 Views)

The column ID is varchar. As previously stated the query works when I leave out the RepairAction search. So I think the problem is with my syntax for declaring an empty string in the SQL query.

 

Thank you,

Jim

0 Kudos
Message 4 of 9
(23,116 Views)

Hi Cerati,

 

 I tried your suggestion, null, and still did not return a record.

 

Thank you. I appreciate your assistance.

 

Jim

0 Kudos
Message 5 of 9
(23,111 Views)
Solution
Accepted by topic author GeekGrok

Jim,

 

Just to be sure, did you use "is" instead of " = " in that command ?

That makes the whole difference in that command.

 

Cerati

0 Kudos
Message 6 of 9
(23,109 Views)

Useful SQL resource (including IS NULL)

 

http://www.w3schools.com/sql/sql_null_values.asp

 

 

 

0 Kudos
Message 7 of 9
(23,104 Views)

Cerati,

 

"is" is the solution. Thank you for pointing out this 'minor' detail. I had initially tested you suggestion using the "=". When I replaced this with "is" per your follow up, the record was read.

 

Thank you again,

JimSmiley Happy

0 Kudos
Message 8 of 9
(23,098 Views)

Okey, I'm glad it worked for you as well Smiley Happy

 

Cheers,

 

Cerati

0 Kudos
Message 9 of 9
(23,095 Views)