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.
| 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) asselect 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_namefrom person ajoin patient_encounter b on a. person_id = b.person_idjoin order_ c on b.person_id = c.person_id and b.enc_id = c.encounteridjoin location_mstr d on b.location_id = d.location_idwhere location_name = @location_name andb.enc_timestamp >= @startdate and c.create_timestamp <= @enddate andc.completedreason <> 'Previously Given'order by c.actstatus descThanks 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 |
 |
|
|
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 |
 |
|
|
|
|
|
|
|