By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Sql Server 2000: How To Handle Null In Select Statement

P: 31
Hi all,

In my table there is a varchar column having NULL and string names.

while i am running select on this table the NULL values are not returned. the statement returns only non null values. my query is

SELECT EMP_ID, AGE FROM EMPLOYEE WHERE EMP_NAME <> 'BABU'

in my table there is records with null values. but it retuns only non null values.

thanks in advance,

dhana.
Mar 15 '08 #1
Share this Question
Share on Google+
5 Replies


100+
P: 144
check like this...

if isdbnull(emp_id)
{
Response.write("Null Values")
}
else
{
Response.write("Not Null Values")
}
Mar 16 '08 #2

ck9663
Expert 2.5K+
P: 2,878
Hi all,

In my table there is a varchar column having NULL and string names.

while i am running select on this table the NULL values are not returned. the statement returns only non null values. my query is

SELECT EMP_ID, AGE FROM EMPLOYEE WHERE EMP_NAME <> 'BABU'

in my table there is records with null values. but it retuns only non null values.

thanks in advance,

dhana.

try:

SELECT EMP_ID, AGE FROM EMPLOYEE WHERE EMP_NAME <> 'BABU' or EMP_NAME is NULL


-- CK
Mar 17 '08 #3

P: 95
There is one exception with %. Not Even the clause where name like '%' will match a row with the value NULL.

create table stu(name varchar(10))
insert into stu values('sona')
insert into stu values('soni')
insert into stu values('sonia')
insert into stu values(NULL)
select * from stu
select * from stu where name like '%'

RESULT--

sona
soni
sonia
Mar 17 '08 #4

P: 95
Hey Ck,the answer given by you was not working, SEE the EXAMPLE BELOW--
create table student(roll int,marks int)
insert into student values(1,10)
insert into student values(2,10)
insert into student values(3,20)
insert into student values(4,NULL)
select * from student
select roll from student where marks <>20 AND marks is NULL

RESULT--BLANK
Mar 17 '08 #5

P: 92
Hey Ck,the answer given by you was not working, SEE the EXAMPLE BELOW--
create table student(roll int,marks int)
insert into student values(1,10)
insert into student values(2,10)
insert into student values(3,20)
insert into student values(4,NULL)
select * from student
select roll from student where marks <>20 AND marks is NULL

RESULT--BLANK

CK's example is correct. You should have used the "OR" operator, instead of "AND".
Mar 17 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.