troubleshooting Question

Link two temp tables to get a result set

Avatar of Becky Edwards
Becky EdwardsFlag for United States of America asked on
Microsoft SQL Server 2008
4 Comments1 Solution212 ViewsLast Modified:
Need to make a temp table look at the results from another temp table and only bring back results based on the list of people's ID's in the first temp table.  I have both queries built and bringing back results.  

Need to know how to link the two temp tables and bring back a result set based on both sets.

Example:
IF OBJECT_ID('tempdb..#TEMP1') IS NOT NULL
      DROP TABLE #TEMP1
GO
SELECT pat_mrn, pat_name, disch_date
INTO #TEMP1
FROM ...
WHERE...
-----then
IF OBJECT_ID('tempdb..#TEMP2') IS NOT NULL
DROP TABLE #TEMP2
GO
SELECT pat.MRN, lab.ID
INTO #TEMP2
FROM...
WHERE...
---now what?
I need the pat_mrn, pat_name, disch_date, lab_id but ONLY if the pat_mrn is in both sets of data.
ASKER CERTIFIED SOLUTION
Mike Eghtebas
Database and Application Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros