View Single Post

   
  #2 (permalink)  
Old 02-29-2008, 05:14 AM
Ryan
 
Posts: n/a
Default Re: Comparing 2 different databases [NEWBIE]

A guess at what you may need...

SELECT
A.CustomerId,
A.CustomerName,
A.CustomerAddress,
B.CustomerName,
B.CustomerAddress,
A.Dividend

FROM
MyServer.FirstDatabase.dbo.FirstList A
LEFT JOIN MyServer.SecondDatabase.dbo.SecondList B
ON A.CustomerId = B.CustomerId

WHERE
A.Dividend <> 0.00 AND
A.Deceased = 0

ORDER BY
A.CustomerName,
B.CustomerName,
A.CustomerAddress,
B.CustomerAddress

I've deliberately left the fields as something obvious (in case anyone
asks about naming standards etc) so that you can see what basic work
you would need to do. Please note, I've used aliases against the table
names as it's always good to do this for ease of reading. I've assumed
that you want everything from the first list (A) and only the records
from the second list (B) - hence the left join.

I've also added a 'Deceased' clause so you can see how to add
additional statements in the WHERE part of the statment. Obviously you
will need to substitute the various fields and databases for your own.

Hope that helps

Ryan


Ben Wehrspann wrote:
> Hello-
>
> I am trying to audit values between 2 different databases.
>
> ie: We send out dividend checks every year, and it is based on how

much
> our customers spend with us. Therefore, once a year we allocate our
> profits to the customers by dumping customer information from the
> billing database to the accounting database. Now the check gets

issued
> from the accounting database after that and the 1099 capital gains

gets
> issued after the check. The time that elapses between the checks and


> 1099's is the problem, because people move, they change their names

etc.
> etc. What I want to do is audit the accounting data against the

current
> billing data. The records have a common account number to join, but

I
> don't know how to form a select (or whatever query it may be) accross


> databases. I've only worked the select from within a single

database.
>
> I would appreciate some help, I am very new to SQL and my experience

is
> limited to the SELECT statement. However, I am willing and

determined
> to learn new and different things.
>
> Thanks in advance,
>
> Ben


Reply With Quote