Home All Groups Group Topic Archive Search About

select from mulitple databases and join

Author
9 Dec 2005 10:47 PM
Paola
Hello,
Im a beginner and need assistance to select from two databases with a join.
db 1 is docs
db 2 is cd
the below query works if i drop the 2nd select value but i want this 2nd
value and join the databases by  docname.
Any ideas or is this not enough info?

SELECT (docs.docsadm.profile.docserver_loc)
+(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS ,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path) AS DOCS2
FROM docs.DOCSADM.COMPONENTS INNER JOIN docs.DOCSADM.PROFILE ON
docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'

Author
9 Dec 2005 11:22 PM
Trey Walpole
how is not working? (errors, unexpected results, etc.)

Paola wrote:
Show quote
> Hello,
> Im a beginner and need assistance to select from two databases with a join.
> db 1 is docs
> db 2 is cd
> the below query works if i drop the 2nd select value but i want this 2nd
> value and join the databases by  docname.
> Any ideas or is this not enough info?
>
> SELECT (docs.docsadm.profile.docserver_loc)
> +(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS
> ,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path) AS DOCS2
> FROM docs.DOCSADM.COMPONENTS INNER JOIN docs.DOCSADM.PROFILE ON
> docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
> WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'
>
>
>
Author
9 Dec 2005 11:35 PM
Paola
WHen i try to put in a join bet the 2 databases, i get syntax errors from
either join or from area.

Paola

Show quote
"Trey Walpole" wrote:

> how is not working? (errors, unexpected results, etc.)
>
> Paola wrote:
> > Hello,
> > Im a beginner and need assistance to select from two databases with a join.
> > db 1 is docs
> > db 2 is cd
> > the below query works if i drop the 2nd select value but i want this 2nd
> > value and join the databases by  docname.
> > Any ideas or is this not enough info?
> >
> > SELECT (docs.docsadm.profile.docserver_loc)
> > +(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS
> > ,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path) AS DOCS2
> > FROM docs.DOCSADM.COMPONENTS INNER JOIN docs.DOCSADM.PROFILE ON
> > docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
> > WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'
> >
> >
> >
>
Author
10 Dec 2005 12:41 AM
Paola
I removed my second join attempt as it wasnt correct. Was hoping that I could
get a tip as to where to place the 2nd join. And unfortunately the docnumbers
are not the same so need to join it by the docname.

Thanks, appreciate the assistance and any input you can provide. Worse case
can do the queries indiividually and combine them in a csv.

Paola

Show quote
"Paola" wrote:

> WHen i try to put in a join bet the 2 databases, i get syntax errors from
> either join or from area.
>
> Paola
>
> "Trey Walpole" wrote:
>
> > how is not working? (errors, unexpected results, etc.)
> >
> > Paola wrote:
> > > Hello,
> > > Im a beginner and need assistance to select from two databases with a join.
> > > db 1 is docs
> > > db 2 is cd
> > > the below query works if i drop the 2nd select value but i want this 2nd
> > > value and join the databases by  docname.
> > > Any ideas or is this not enough info?
> > >
> > > SELECT (docs.docsadm.profile.docserver_loc)
> > > +(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS
> > > ,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path) AS DOCS2
> > > FROM docs.DOCSADM.COMPONENTS INNER JOIN docs.DOCSADM.PROFILE ON
> > > docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
> > > WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'
> > >
> > >
> > >
> >
Author
11 Dec 2005 4:53 PM
Erland Sommarskog
Paola (Pa***@discussions.microsoft.com) writes:
> I removed my second join attempt as it wasnt correct. Was hoping that I
> could get a tip as to where to place the 2nd join. And unfortunately the
> docnumbers are not the same so need to join it by the docname.
>
> Thanks, appreciate the assistance and any input you can provide. Worse
> case can do the queries indiividually and combine them in a csv.

It's difficult to give suggestions when I don't understand what you are
trying to do.

The recommended procedure is that you include:

1)  CREATE TABLE statements for your tables.
2)  INSERT statements with sample data.
3)  The desired output given the sample
4)  A short narrative of the purpose.

There are several reasons why this is good:
a) With the given data, it's easy to copy and past into Query Analyzer
   and develop a tested solution.
b) The solution is more likely to be useful, as it is not based on
   guesses.
c) By developing a test case, you also improve the quality on your own
   work.

I should add that the fact that the tables are in different databases
is not much of an issue. That's the easy part.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
9 Dec 2005 11:35 PM
Trey Walpole
sorry, going cross-eyed this time of day...

i don't see where you're actually trying to join to the second database.
would the other database have the same docnumber for the component? or
is it based only on the docname?

e.g.
if same docnumber

SELECT (docs.docsadm.profile.docserver_loc)
+(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS
,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path)

AS DOCS2
FROM docs.DOCSADM.COMPONENTS
INNER JOIN docs.DOCSADM.PROFILE
ON docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
INNER JOIN cd.DOCSADM.PROFILE
ON docs.DOCSADM.PROFILE.DOCNUMBER = cd.DOCSADM.PROFILE.DOCNUMBER
INNER JOIN cd.DOCSADM.PROFILE
ON cd.DOCSADM.COMPONENTS.DOCNUMBER = cd.DOCSADM.PROFILE.DOCNUMBER
WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'


e.g.
if same docname

SELECT (docs.docsadm.profile.docserver_loc)
+(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS
,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path)

AS DOCS2
FROM docs.DOCSADM.COMPONENTS
INNER JOIN docs.DOCSADM.PROFILE
ON docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
INNER JOIN cd.DOCSADM.PROFILE
ON docs.DOCSADM.PROFILE.DOCNAME = cd.DOCSADM.PROFILE.DOCNAME
INNER JOIN cd.DOCSADM.PROFILE
ON cd.DOCSADM.COMPONENTS.DOCNUMBER = cd.DOCSADM.PROFILE.DOCNUMBER
WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'



Trey Walpole wrote:
Show quote
> how is not working? (errors, unexpected results, etc.)
>
> Paola wrote:
>
>> Hello,
>> Im a beginner and need assistance to select from two databases with a
>> join.
>> db 1 is docs
>> db 2 is cd
>> the below query works if i drop the 2nd select value but i want this
>> 2nd value and join the databases by  docname.
>> Any ideas or is this not enough info?
>>
>> SELECT (docs.docsadm.profile.docserver_loc)
>> +(docs.docsadm.profile.path)+(docs.docsadm.components.path) AS DOCS
>> ,(cd.docsadm.profile.docserver_loc)+(cd.docsadm.profile.path)+(cd.docsadm.components.path)
>> AS DOCS2
>> FROM docs.DOCSADM.COMPONENTS INNER JOIN docs.DOCSADM.PROFILE ON
>> docs.DOCSADM.COMPONENTS.DOCNUMBER = docs.DOCSADM.PROFILE.DOCNUMBER
>> WHERE docs.DOCSADM.PROFILE.DOCNAME='Backup'
>>
>>
>>

AddThis Social Bookmark Button