Wednesday, March 21, 2012

Joining tbls from different db's with WHERE statement

Hi,
This is the first time I've joined tables residing on seperate databases. It
works without the WHERE statement, but when I add the WHERE clause in, it
returns no rows. I am certain the argument is correct & have used it in a
simple table and it returns rows. Is there something specal about doing this
against two tables from different DB's
Thanks for any clues.
Ant
SELECT i.Log_id,
e.name,
e.tel,
e.email,
i.TimeSubmit,
i.Priority,
i.Status,
i.ProDes,
i.emp_id
FROM IDB.dbo.IRL i
INNER JOIN NDB.dbo.Employees e ON i.emp_id = e.emp_id
WHERE i.Status = 'Open'Could it be that only a small number of records in table IRL have a status
of open, by INNER JOINing to Employee you eleminate the small number. Try
this to find out...
SELECT i.Log_ID, i.Status , i.emp_id, e.emp_id
FROM IDB.dbo.IRL i
LEFT JOIN NDB.dbo.Employees e ON i.emp_id = e.emp_id
WHERE i.Status = 'Open'
HTH. Ryan
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:A82B8A64-7986-417D-B34F-3B6EE50928C2@.microsoft.com...
> Hi,
> This is the first time I've joined tables residing on seperate databases.
> It
> works without the WHERE statement, but when I add the WHERE clause in, it
> returns no rows. I am certain the argument is correct & have used it in a
> simple table and it returns rows. Is there something specal about doing
> this
> against two tables from different DB's
> Thanks for any clues.
> Ant
> SELECT i.Log_id,
> e.name,
> e.tel,
> e.email,
> i.TimeSubmit,
> i.Priority,
> i.Status,
> i.ProDes,
> i.emp_id
> FROM IDB.dbo.IRL i
> INNER JOIN NDB.dbo.Employees e ON i.emp_id = e.emp_id
> WHERE i.Status = 'Open'

No comments:

Post a Comment