473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to Eliminate NULL values from the SQL queries

ssue:
------
I am working on a health care system and currently facing problem with NULL values being introduced as part of my SQL query.

What is the query trying to do?
The query is trying to retrieve ids from summary table for a practice where the patient are dead and find out if there are same patients in other systems like clinics or hospitals where this patient might still be showing as alive. This is basically a data cleansing query.

Expand|Select|Wrap|Line Numbers
  1. DECLARE @REGION char(1)
  2. SET @REGION = 'A'
  3.  
  4. DECLARE @PRAC_ID varchar(5)
  5. SET @PRAC_ID = '11111'
  6.  
  7.  
  8.         SELECT  Max(D.DATAAGE) DATAAGE, 
  9.                 ds.LINK_ID, 
  10.                 D.PAT_ID, 
  11.                 ds.FName1, 
  12.                 ds.Surname, 
  13.                 D.PRAC_ID, 
  14.                 D.DataSource_ID, 
  15.                 DS.DataSource_Description, 
  16.                 DS.Primary_Care_System , 
  17.                 @REGION as Region
  18.         FROM         Demography D, 
  19.                 Demography_Summary ds, 
  20.                 DataSource_IDs DS
  21.         WHERE         ds.LINK_ID = D.LINK_ID
  22.                 AND ds.LINK_ID IN
  23.                 (
  24.         SELECT         LINK_ID
  25.         FROM         Demography_Summary 
  26.         WHERE         DEAD =  1
  27.                 AND PRAC_ID = @PRAC_ID
  28.                 AND Status < 2
  29.                 )
  30.         AND D.DataSource_ID = DS.DataSource_ID
  31.         AND (DS.Primary_Care_System = 1 OR DS.Secondary_Care_Clinic = 1)        
  32.         AND D.DataSource_ID <> 36 
  33.         AND D.DEAD = 0
  34.         AND D.Status < 2        
  35.         GROUP BY ds.LINK_ID, 
  36.                 D.PAT_ID, 
  37.                 ds.FName1, 
  38.                 ds.Surname, 
  39.                 D.PRAC_ID,
  40.                 D.DataSource_ID, 
  41.                 DS.DataSource_Description, 
  42.                 DS.Primary_Care_System 
  43.         ORDER BY ds.Surname, ds.FName1 
  44.  
Result shown:
2007-02-26 00:00:00.000 201295648 1402203330 Testing Test 22222 50 clinic1, Primary Care 1 T
2008-05-06 15:53:40.077 201295648 1402203330 Testing Test NULL 50 clinic1, Primary Care 1 T

Now I don't want the second row that is showing a NULL value for Practice ID (as they are not a valid value for practice id ) and only the first row needs to be shown.

I have tried using D.PRAC_ID is NOT NULL but it doesnt seem to work. I have even tried a sub query to eliminate PRAC_IDs with NULL but the problem is that the value that needs to be considered has same LINK_ID as that of PRAC_ID = null. Can anyone help with this please.

Thanks in advance,
Sree
May 7 '08 #1
1 3623
ssue:
------
I am working on a health care system and currently facing problem with NULL values being introduced as part of my SQL query.

What is the query trying to do?
The query is trying to retrieve ids from summary table for a practice where the patient are dead and find out if there are same patients in other systems like clinics or hospitals where this patient might still be showing as alive. This is basically a data cleansing query.

Expand|Select|Wrap|Line Numbers
  1. DECLARE @REGION char(1)
  2. SET @REGION = 'A'
  3.  
  4. DECLARE @PRAC_ID varchar(5)
  5. SET @PRAC_ID = '11111'
  6.  
  7.  
  8.         SELECT  Max(D.DATAAGE) DATAAGE, 
  9.                 ds.LINK_ID, 
  10.                 D.PAT_ID, 
  11.                 ds.FName1, 
  12.                 ds.Surname, 
  13.                 D.PRAC_ID, 
  14.                 D.DataSource_ID, 
  15.                 DS.DataSource_Description, 
  16.                 DS.Primary_Care_System , 
  17.                 @REGION as Region
  18.         FROM         Demography D, 
  19.                 Demography_Summary ds, 
  20.                 DataSource_IDs DS
  21.         WHERE         ds.LINK_ID = D.LINK_ID
  22.                 AND ds.LINK_ID IN
  23.                 (
  24.         SELECT         LINK_ID
  25.         FROM         Demography_Summary 
  26.         WHERE         DEAD =  1
  27.                 AND PRAC_ID = @PRAC_ID
  28.                 AND Status < 2
  29.                 )
  30.         AND D.DataSource_ID = DS.DataSource_ID
  31.         AND (DS.Primary_Care_System = 1 OR DS.Secondary_Care_Clinic = 1)        
  32.         AND D.DataSource_ID <> 36 
  33.         AND D.DEAD = 0
  34.         AND D.Status < 2        
  35.         GROUP BY ds.LINK_ID, 
  36.                 D.PAT_ID, 
  37.                 ds.FName1, 
  38.                 ds.Surname, 
  39.                 D.PRAC_ID,
  40.                 D.DataSource_ID, 
  41.                 DS.DataSource_Description, 
  42.                 DS.Primary_Care_System 
  43.         ORDER BY ds.Surname, ds.FName1 
  44.  
Result shown:
2007-02-26 00:00:00.000 201295648 1402203330 Testing Test 22222 50 clinic1, Primary Care 1 T
2008-05-06 15:53:40.077 201295648 1402203330 Testing Test NULL 50 clinic1, Primary Care 1 T

Now I don't want the second row that is showing a NULL value for Practice ID (as they are not a valid value for practice id ) and only the first row needs to be shown.

I have tried using D.PRAC_ID is NOT NULL but it doesnt seem to work. I have even tried a sub query to eliminate PRAC_IDs with NULL but the problem is that the value that needs to be considered has same LINK_ID as that of PRAC_ID = null. Can anyone help with this please.

Thanks in advance,
Sree
Hi all,

The issue was with data, it was TEXT NULL and not a actual NULL as such and hence it was not getting eliminated through IS NULL or IS NOT NULL. Changed the data and its works beautifully.

Cheers,
Sree
May 7 '08 #2

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

Similar topics

3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
3
by: FZ | last post by:
Hi gang, I was wondering if someone would be kind enough to help me with the following problem. I have created a report that prints shipping labels. The problem is that I have some customers...
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
2
by: George G. | last post by:
Hi there, I hope I am posting to the correct news group. What would be a good way to deal with null database values using ADO.NET. My SQL queries sometimes return null values when I have left...
13
by: Federico Balbi | last post by:
Hi, I was wondering if PGSQL has a function similar to binary_checksum() of MS SQL Server 2000. It is pretty handy when it comes to compare rows of data instead of having to write long boolean...
4
by: Eric Layman | last post by:
Hi everyone, Im puzzled by a NULL behaviour in SQL 2000 server. There is a column in the table that does not allow NULL. During data mining, the staff noted that, for that particular column,...
9
by: Yitzak | last post by:
Hi spent a few hours on this one wrote a query that joined on results of 2 other queries. Qry3 using Qry1 and Qry2 When I used Qry1.FasText <cstr(Qry2.FasInteger) in the where clause - got...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.