2

I have a query in SQL where I need to add a condition, to find all the records that have an empty field.

This gave me an error..

SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma 
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE SMS_MONTIME.IDTICKET ==''

Thanks

mplungjan
  • 169,008
  • 28
  • 173
  • 236
ossial
  • 23
  • 1
  • 7
  • Change =='' to ='' just one '=' sign, or use the datalength function as explained here: http://stackoverflow.com/a/33425/752527 – Hanlet Escaño Dec 18 '12 at 09:30

4 Answers4

1

In query use just = for checking not == and for checking null values use is null

SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma 
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE SMS_MONTIME.IDTICKET ='' or SMS_MONTIME.IDTICKET is null
senK
  • 2,782
  • 1
  • 27
  • 38
1

Try this:

...
WHERE SMS_MONTIME.IDTICKET = '' OR SMS_MONTIME.IDTICKET IS NULL

The issue is, what does "blank" mean: '' or null or more usually both

Also, use = not == (I've never actually tried ==, but I've never seen anyone else either, so it can't be good)

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

try this

"SELECT 
 forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
  FROM forma 
  LEFT JOIN 
   SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE SMS_MONTIME.IDTICKET =''"

or try this

 WHERE SMS_MONTIME.IDTICKET is null

for not null use

WHERE SMS_MONTIME.IDTICKET is not null
SRIRAM
  • 1,888
  • 2
  • 17
  • 17
0

to check an empty field, i.e NULL field one can't use =. U have to use the IS NULL Your query should be like this

SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma 
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET 
WHERE SMS_MONTIME.IDTICKET IS NULL
Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71