Click here to Skip to main content
15,881,819 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sql query with != condition not working
my query is
SQL
Select regno from member_master where parentregnoM=2 and parentPosM=1 and registerAS  != 'Free'


not giving me any result
but when i write the query like
SQL
Select regno from member_master where parentregnoM=2 and parentPosM=1


show me right result
where in registerAS field values are null so first query also shows the results
Posted
Comments
dimpledevani 31-Dec-12 1:02am    
use <> in sql for checking 'not equal to'
ridoy 31-Dec-12 1:15am    
I try with your queries in my case,it works fine whether it is != or <> because both are valid in sql,but i think your registerAS column of your database may be null which may cause this problem,and look below Mika Wendelius gave you a solution on that case..
Amir Mahfoozi 6-Jan-13 2:08am    
Please tell us what the registerAS data type is?

If the column RegisterAs is null, you could try the following
SQL
SELECT regno 
FROM   member_master 
WHERE  parentregnoM = 2 
AND    parentPosM   = 1 
AND    (   registerAS  != 'Free'
       OR  registerAS  IS NULL)
 
Share this answer
 
Comments
ridoy 31-Dec-12 1:16am    
+5
Wendelius 31-Dec-12 1:29am    
Thanks :-D
__TR__ 31-Dec-12 4:54am    
5ed!
Wendelius 2-Jan-13 3:35am    
Thanks :)
Hi ,

try the below one

SQL
SELECT regno
FROM   member_master WHERE  parentregnoM = 2 AND    parentPosM   = 1
AND    (   registerAS  != 'Free'
       OR  registerAS  IS NULL)
 
Share this answer
 
instead of !=
use... <>
Happy Coding!
:)
 
Share this answer
 
Comments
Miss Maheshwari 31-Dec-12 0:54am    
already tried both <> and !=
Aarti Meswania 31-Dec-12 0:58am    
you mean to say it's still giving records which registerAs value is 'free' ?
Miss Maheshwari 31-Dec-12 1:02am    
Select regno from member_master where parentregnoM=2 and parentPosM=1 and registerAS != 'Free'
or
Select regno from member_master where parentregnoM=2 and parentPosM=1 and registerAS <> 'Free'

not giving any result/record
but when i write query like

Select regno from member_master where parentregnoM=2 and parentPosM=1
showing me result
Aarti Meswania 31-Dec-12 1:04am    
can you paste some output records?
Just use this

SQL
Select regno from member_master where parentregnoM=2 and parentPosM=1 and (registerAS  != 'Free')

or
SQL
Select regno from member_master where parentregnoM=2 and parentPosM=1 and (registerAS  <> 'Free')


Use () for your query... != , <> both are same...

Accept The Solution if you find it works for you so that it helps others also...

Thanks
Developers Blog[^]
Hemant Singh Rautela
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900