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 2005 Forums
 Transact-SQL (2005)
 Select NULL

Author  Topic 

sross81
Posting Yak Master

228 Posts

Posted - 2009-05-18 : 16:42:04
Hello,

I have a table where one of the columns (c.CompletedReason) actual data value is the word NULL when there is nothing inputted into the form. Sometimes there is other entries made its basically like a field where users make comments. I want to be able to select all records that are not equal to "Previously Given" but when I do this all the ones that have the word NULL are excluded as well. I am not sure why that is?? Does anyone have any ideas? Here is the code I am using:

alter procedure [dbo].[emr_immuzorderrpt] (@location_name varchar(40),
@startdate as datetime,@enddate as datetime) as


select distinct a.last_name,a.first_name,cast(a.date_of_birth as datetime) as PtDOB,
b.enc_nbr,b.enc_timestamp,c.actclass,c.actcode,c.completedreason,
c.actstatus,c.acttext,d.location_name
from person a
join patient_encounter b on a. person_id = b.person_id
join order_ c on b.person_id = c.person_id and b.enc_id = c.encounterid
join location_mstr d on b.location_id = d.location_id
where location_name = @location_name and
b.enc_timestamp >= @startdate and c.create_timestamp <= @enddate and
c.completedreason <> 'Previously Given'
order by c.actstatus desc





Thanks in Advance!
Sherri

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2009-05-18 : 17:10:27
Are you SURE that the actual data value is the word NULL? The SQL Tools may display the word NULL on-screen when there is no value (i.e. real NULL). And if there is no value (null) then the way to test for that is to use the keywords IS NULL rather than equality or inequality.

In other words...

WHERE c.completedreason IS NULL or c.completedreason <> 'Previously Given'


--------------------------------------------
Brand yourself at EmeraldCityDomains.com
Go to Top of Page

sross81
Posting Yak Master

228 Posts

Posted - 2009-05-18 : 17:53:46
putting this or statement like this in my where statment did exactly what I needed it to do. Thanks!

(c.completedreason IS NULL or c.completedreason <> 'Previously Given')

quote:
Originally posted by AjarnMark

Are you SURE that the actual data value is the word NULL? The SQL Tools may display the word NULL on-screen when there is no value (i.e. real NULL). And if there is no value (null) then the way to test for that is to use the keywords IS NULL rather than equality or inequality.

In other words...

WHERE c.completedreason IS NULL or c.completedreason <> 'Previously Given'


--------------------------------------------
Brand yourself at EmeraldCityDomains.com



Thanks in Advance!
Sherri
Go to Top of Page
   

- Advertisement -