cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 

SQL query for empty string

¡Resuelto!
Ir a solución

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
Mensaje 1 de 9
26.265 Vistas

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
Mensaje 2 de 9
26.260 Vistas

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
Mensaje 3 de 9
26.189 Vistas

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
Mensaje 4 de 9
26.186 Vistas

Hi Cerati,

 

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

 

Thank you. I appreciate your assistance.

 

Jim

0 kudos
Mensaje 5 de 9
26.181 Vistas
Solución
Aceptado por el autor del tema 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
Mensaje 6 de 9
26.179 Vistas

Useful SQL resource (including IS NULL)

 

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

 

 

 

0 kudos
Mensaje 7 de 9
26.174 Vistas

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,

JimEmoticono feliz

0 kudos
Mensaje 8 de 9
26.168 Vistas

Okey, I'm glad it worked for you as well Emoticono feliz

 

Cheers,

 

Cerati

0 kudos
Mensaje 9 de 9
26.165 Vistas