Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how to select 'null' values when use 'between'

Author  Topic 

myheart46
Starting Member

13 Posts

Posted - 2003-11-28 : 21:30:56
example
select name from customer
where name between 'x1' and 'x2';
if x1=0 and x2=z
all record will show but name that has null will not show
then i use
select name from customer
where name between 'x1' and 'x2' or name is null;
if x1='john' and x2='john'
it show john and name that has null values
plzz help me
thx so much

nr
SQLTeam MVY

12543 Posts

Posted - 2003-11-28 : 21:51:30
in an equality null will always return null which evaluates to false.
???? not sure what you expect to happen
where name between 'x1' and 'x2'
name = null gives null so the record is not returned

where name between 'x1' and 'x2'
or name is null

for null
name between 'x1' and 'x2' returns false
name is null returns true

as there is an or condition the clause evaluates to true and the record is returned.



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

myheart46
Starting Member

13 Posts

Posted - 2003-11-28 : 22:21:59
my question is
where name between :parameter1 and :parameter2
what parameter1 and 2 that make select code return all record in table
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-11-28 : 22:50:49
It's not possible for that to include null values

where coalesce(fld,'a') between 'a' and 'z'
will include the null values for fld but it's not possible without catering explicitely for null.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -