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. -
DECLARE @REGION char(1)
-
SET @REGION = 'A'
-
-
DECLARE @PRAC_ID varchar(5)
-
SET @PRAC_ID = '11111'
-
-
-
SELECT Max(D.DATAAGE) DATAAGE,
-
ds.LINK_ID,
-
D.PAT_ID,
-
ds.FName1,
-
ds.Surname,
-
D.PRAC_ID,
-
D.DataSource_ID,
-
DS.DataSource_Description,
-
DS.Primary_Care_System ,
-
@REGION as Region
-
FROM Demography D,
-
Demography_Summary ds,
-
DataSource_IDs DS
-
WHERE ds.LINK_ID = D.LINK_ID
-
AND ds.LINK_ID IN
-
(
-
SELECT LINK_ID
-
FROM Demography_Summary
-
WHERE DEAD = 1
-
AND PRAC_ID = @PRAC_ID
-
AND Status < 2
-
)
-
AND D.DataSource_ID = DS.DataSource_ID
-
AND (DS.Primary_Care_System = 1 OR DS.Secondary_Care_Clinic = 1)
-
AND D.DataSource_ID <> 36
-
AND D.DEAD = 0
-
AND D.Status < 2
-
GROUP BY ds.LINK_ID,
-
D.PAT_ID,
-
ds.FName1,
-
ds.Surname,
-
D.PRAC_ID,
-
D.DataSource_ID,
-
DS.DataSource_Description,
-
DS.Primary_Care_System
-
ORDER BY ds.Surname, ds.FName1
-
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
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. -
DECLARE @REGION char(1)
-
SET @REGION = 'A'
-
-
DECLARE @PRAC_ID varchar(5)
-
SET @PRAC_ID = '11111'
-
-
-
SELECT Max(D.DATAAGE) DATAAGE,
-
ds.LINK_ID,
-
D.PAT_ID,
-
ds.FName1,
-
ds.Surname,
-
D.PRAC_ID,
-
D.DataSource_ID,
-
DS.DataSource_Description,
-
DS.Primary_Care_System ,
-
@REGION as Region
-
FROM Demography D,
-
Demography_Summary ds,
-
DataSource_IDs DS
-
WHERE ds.LINK_ID = D.LINK_ID
-
AND ds.LINK_ID IN
-
(
-
SELECT LINK_ID
-
FROM Demography_Summary
-
WHERE DEAD = 1
-
AND PRAC_ID = @PRAC_ID
-
AND Status < 2
-
)
-
AND D.DataSource_ID = DS.DataSource_ID
-
AND (DS.Primary_Care_System = 1 OR DS.Secondary_Care_Clinic = 1)
-
AND D.DataSource_ID <> 36
-
AND D.DEAD = 0
-
AND D.Status < 2
-
GROUP BY ds.LINK_ID,
-
D.PAT_ID,
-
ds.FName1,
-
ds.Surname,
-
D.PRAC_ID,
-
D.DataSource_ID,
-
DS.DataSource_Description,
-
DS.Primary_Care_System
-
ORDER BY ds.Surname, ds.FName1
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |