RE: Select across databases

From: John Bell (JohnBell_at_discussions.microsoft.com)
Date: 09/15/04


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
>
>
>



Relevant Pages

  • Re: selecting records based on the position in the database
    ... >You have a date time stamp field? ... >ORDER BY dateTime DESC; ... >> I need to write a query for a database that needs to ...
    (microsoft.public.access.queries)
  • Speeding up call to a remote table
    ... I've got a SQL Query created to pull aggregate values from a linked ... Declare @StartDate as datetime ... Declare @EndDate as datetime ...
    (microsoft.public.sqlserver.programming)
  • Outer join problem with 2 different alias for same table.
    ... I am testing a SQL query on 2 "almost" identical databases. ... The problem is that this query is working fine on the first database ... I dont understand why it could work when I declare the ... AstInstrument ...
    (comp.databases.sybase)
  • Re:Date Problem
    ... create table test(dt datetime) ... declare @dt varchar ... >database using asp.net. ... mm/dd/yyyy format. ...
    (microsoft.public.sqlserver.security)
  • Re: Bulding expressions in views
    ... If iStdtand iDateare of type datetime: ... declare @iStdt2 datetime ... query, you should store the value in a local variable whenever possible. ... WHERE (dDatez BETWEEN dbo. ...
    (microsoft.public.access.adp.sqlserver)