Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do a Not Equal condition t 2

Status
Not open for further replies.

lobstah

Programmer
May 14, 2001
384
US
How do I do a Not Equal condition to a text field? Is the following correct? I do not get any records returned when I should. If I remove the &quot;fd.export_flag <> 'y'&quot; portion, it selects all the records, as it should.

SELECT * FROM Form_Data fd, Users u
WHERE fd.export_flag <> 'y'
AND u.user_id = fd.user_id

Thank you in advance for your help.
 
That is the correct statement for a not equal condition. The select from is what is bothering me. I am not sure what you are selecting from.
 
solved my problem. apparently if the field is empty, it doesn't compare correctly? anyway, with data in the field, it works.
 
You might want to try a join condition on those 2 tables rather than selecting from 2 tables that way.
 
Lobstah,

I just want to follow up on Bryant89's tip and the solution you found. I agree that you should use ANSI Join syntax. This will separate the Join criteria from the selection criteria. Once you become used to the syntax it makes a lot of sense and is easier to understand.

A NULL column cannot be tested for equal or not equal. You must check for Null or do as you did and fill the column with data. I recommend the following query for your consideration.
[/tt]
SELECT *
FROM Form_Data fd
INNER JOIN Users u
ON fd.user_id = u.user_id

WHERE fd.export_flag <> 'y'
OR fd.export_flag Is Null[/tt] Terry L. Broadbent
Programming and Computing Resources
 
Excellent Terry!! Worked like a charm, thank you so much!

Thank you and Bryant89!!

:-D

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top