elsenorjose
Technical User
Hello everyone,
I am a relative novice when it comes to SQL but can usually write queries that retrieve data as needed. However, I have a problem that my limited skillset can't solve.
I need to create a view that restricts data by eliminating records where a date exists in two tables. The area is drug manufacturing lot samples. I have two tables LOT and LOT_SAMPLING_POINT. In LOT, there exists a DATE_CREATED which is when a drum sample arrives. In LOT_SAMPLING_POINT, there exists DISPOSITION_DATE which is when that drug sample is approved.
I can have multiple rows in LOT_SAMPLING_POINT for one lot but typically only one row in LOT. My challenge is to exclude records from both tables when a date exists for DATE_CREATED and DISPOSITION_DATE, as well as when NULLs exist. Here is some sample data based on a LEFT OUTER JOIN of both tables.
In my view, I would not want any of these records to be included since there is at least one instance of a date_created and disposition_date for each lot.
I wrote the following but it is only eliminating the record that has both a date_created and a disposition_date:
Like I mentioned, my SQL skills are limited to pretty much just querying for data retrieval so I'm not very well versed in cursors or stored procedures but it looks like that might be the approach to take? Can anyone help with a solution as well as some teaching?
Thank you
I am a relative novice when it comes to SQL but can usually write queries that retrieve data as needed. However, I have a problem that my limited skillset can't solve.
I need to create a view that restricts data by eliminating records where a date exists in two tables. The area is drug manufacturing lot samples. I have two tables LOT and LOT_SAMPLING_POINT. In LOT, there exists a DATE_CREATED which is when a drum sample arrives. In LOT_SAMPLING_POINT, there exists DISPOSITION_DATE which is when that drug sample is approved.
I can have multiple rows in LOT_SAMPLING_POINT for one lot but typically only one row in LOT. My challenge is to exclude records from both tables when a date exists for DATE_CREATED and DISPOSITION_DATE, as well as when NULLs exist. Here is some sample data based on a LEFT OUTER JOIN of both tables.
Code:
date_created disposition_date lot_number
3/4/2009 3/10/2009 003079AX10
3/4/2009 NULL 003079AX10
10/13/2010 11/12/2010 BN1002B
10/13/2010 NULL BN1002B
10/13/2010 NULL BN1002B
In my view, I would not want any of these records to be included since there is at least one instance of a date_created and disposition_date for each lot.
I wrote the following but it is only eliminating the record that has both a date_created and a disposition_date:
Code:
select
lims.lot.date_created
, lims.lot_sampling_point.disposition_date
, lims.lot.lot_name
from lims.lot left outer join lims.lot_sampling_point
on lims.lot.lot_name = lims.lot_sampling_point.lot_name
where not (date_created is not null and disposition_date is not null)
Like I mentioned, my SQL skills are limited to pretty much just querying for data retrieval so I'm not very well versed in cursors or stored procedures but it looks like that might be the approach to take? Can anyone help with a solution as well as some teaching?
Thank you