Join Query, two tables, two databases?

  • Is that possible?  To have two databases with one query?  If so the query below should populate some data!  If not, how can I accomplish the task?

    SELECT JobSheet.dbo.JobHrs.JobNo, JobSheet.dbo.JobHrs.ActualHrs, JobSheet.dbo.JobHrs.ReworkHrs, TimeReporting.dbo.TimeData.Time, TimeReporting.dbo.TimeData.Rework

    FROM JobSheet.dbo.JobHrs

    INNER JOIN TimeReporting.dbo.TimeData ON JobSheet.dbo.JobHrs.JobNo = TimeReporting.dbo.TimeData.JobNo

    WHERE JobSheet.dbo.JobHrs.JobNo = '19-0228B'

     

    Steve Anderson

  • Yes, it's possible.  A SELECT statement won't populate any data, though.  What exactly are you trying to do?

    John

  • This is great because yes, it runs but populates no data.

    Tried this as well:

    SELECT T1.JobNo, T1.ActualHrs, T1.ReworkHrs , T2.Time, T2.Rework

    FROM JobSheet.dbo.JobHrs T1

    INNER JOIN TimeReporting.dbo.TimeData T2 ON T1.JobNo = T2.JobNo

    WHERE T1.JobNo = '19-0228B'

     

    In actuality, I want to read the field TimeData.Time from one database table, and populate it in JobHrs.ActualHrs in another database table.  I am actually wanting to place a query in a Typed Dataset in Visual Studio.

    Steve Anderson

  • Populate data vs show data, my dilemma is that I see no data for my query at all.  I don't agree that this should be the case, unless there is a another way to accomplish this.  I'm not looking for the Visual Studio solution here, but what is the solution?

     

    Steve Anderson

  • This is your query:

    SELECT T1.JobNo, T1.ActualHrs, T1.ReworkHrs , T2.Time, T2.Rework

    FROM JobSheet.dbo.JobHrs T1

    INNER JOIN TimeReporting.dbo.TimeData T2 ON T1.JobNo = T2.JobNo

    WHERE T1.JobNo = '19-0228B'

    If you are getting no data, then check these items:

    1. There is no T1.JobNo  '19-0228B'.  Remove the WHERE clause, and see if any rows are returned
    2. The table JobSheet.dbo.JobHrs has no matching rows to TimeReporting.dbo.TimeData on the JobNo column.  Try changing to a left join and see if any rows are returned.

     

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply