Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
sql query with != condition not working
my query is
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
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 30-Dec-12 19:42pm
Comments
dimpledevani at 31-Dec-12 1:02am
   
use <> in sql for checking 'not equal to'
ridoy at 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 at 6-Jan-13 2:08am
   
Please tell us what the registerAS data type is?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If the column RegisterAs is null, you could try the following
SELECT regno 
FROM   member_master 
WHERE  parentregnoM = 2 
AND    parentPosM   = 1 
AND    (   registerAS  != 'Free'
       OR  registerAS  IS NULL)
  Permalink  
Comments
ridoy at 31-Dec-12 1:16am
   
+5
Mika Wendelius at 31-Dec-12 1:29am
   
Thanks :-D
__TR__ at 31-Dec-12 4:54am
   
5ed!
Mika Wendelius at 2-Jan-13 3:35am
   
Thanks :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi ,
 
try the below one
 
SELECT regno
FROM   member_master WHERE  parentregnoM = 2 AND    parentPosM   = 1
AND    (   registerAS  != 'Free'
       OR  registerAS  IS NULL)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

instead of !=
use... <>
Happy Coding!
Smile | :)
  Permalink  
Comments
Miss Maheshwari at 31-Dec-12 0:54am
   
already tried both <> and !=
Aarti Meswania at 31-Dec-12 0:58am
   
you mean to say it's still giving records which registerAs value is 'free' ?
Miss Maheshwari at 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 at 31-Dec-12 1:04am
   
can you paste some output records?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Just use this
 
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')
 
 
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
  Permalink  
v6

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

  Print Answers RSS
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 6 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100