RE: Select across databases
From: John Bell (JohnBell_at_discussions.microsoft.com)
Date: 09/15/04
- Next message: A Traveler: "Re: a Non-Aggregate Cross-Tab?"
- Previous message: Adam Machanic: "Re: a Non-Aggregate Cross-Tab?"
- In reply to: Gerry Viator: "Select across databases"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 15 Sep 2004 11:27:05 -0700
Hi Gerry
It's not deemed good production code to have select *, as you may be using
too much bandwidth, unless you are using the EXISTS clause that is! Add to
the query:
WHERE EXISTS ( SELECT *
FROM Eus.dbo.patientclinical
WHERE hosp_no = tempdemo.hospno )
John
"Gerry Viator" wrote:
> Hi all,
>
> I need to also check if tempdemo.hospno is in another database:
> Eus.dbo.patientclinical.hosp_no
>
> How would I add this to the query? I only want to pull the one's the are
> also in the other database.
>
>
> DECLARE @startdate AS DATETIME
> SET @startdate = '1996-1-1'
>
> DECLARE @EndDate AS DATETIME
> SET @EndDate = '1999-12-31'
>
>
> SELECT tempdemo.*, tempercp.*
> FROM tempdemo JOIN
> tempercp ON tempdemo.Hospno = tempercp.Hospno
> where (SELECT CASE
> WHEN dateadd(year, datediff (year, birthdate,
> examdate),birthdate) > examdate
> THEN datediff (year, birthdate, examdate) - 1
> ELSE datediff (year, birthdate, examdate)
> END )<= '65'
>
> and (pancreas = 'normal' or pancreas2 = 'normal' or
> pancreas3 = 'normal')
> and final_Diagnosis not in('papillary
> adenoma','papillary cancer','pancreatic cancer',
> 'islet cell tumor','biliary cancer (non-hilar)',
> 'biliary cancer (hilar)','gallbladder
> cancer','primary hepatoma', 'hepatic metastases')
> and examdate between @startdate and @EndDate
>
> order by birthdate
>
>
>
- Next message: A Traveler: "Re: a Non-Aggregate Cross-Tab?"
- Previous message: Adam Machanic: "Re: a Non-Aggregate Cross-Tab?"
- In reply to: Gerry Viator: "Select across databases"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|