glthornton
Programmer
Hi everyone, (DB Info: SQL Server 2000). I'm currently working on a project for our hospital to participate in our states RHIO. What I need to do is create sql queries that will check to see if certain values (BP, Height, Weight, etc.) has been added to a patient record within the past 24 hours. There queries are all written, but what I need help with is to create a stored procedure that will store the patient's MRN and Visit ID in a single table. So for example, I have a Blood Pressure query that returns the MRN and VISITID. I want to store it in the following table (dbo.vtrhio_daily). So the BP data into this table will look like this:
Now I need to run say the Height query. I'm going to extract the same data fields as the BP query and I want to add my results into the same table where the MRN and VISITID do not already exist. So for example, if my Height query as a standalone returns this:
As you can see the first 2 rows already exist and I only need to add the last 2 rows. Which would now look like this:
How would I do this in a stored procedure? I thought I could use and WHERE NOT EXISTS command, but I'm not a DBA.
Kind regards, Glenn
Code:
[b][u]vtrhio_daily[/u][/b]
MRN VISITID
1234 33123
2345 33234
3456 33345
4567 33456
Now I need to run say the Height query. I'm going to extract the same data fields as the BP query and I want to add my results into the same table where the MRN and VISITID do not already exist. So for example, if my Height query as a standalone returns this:
Code:
[b][u]HEIGHT[/u][/b]
MRN VISITID
1234 33123
2345 33234
5678 33678
6789 33789
Code:
[b][u]vtrhio_daily[/u][/b]
MRN VISITID
1234 33123
2345 33234
3456 33345
4567 33456
5678 33678
6789 33789
Kind regards, Glenn