How to select from different databases?

  • Hi expert,

    I want to select from different databases (HFC and HFC_EPAY) but it gives me an error: Invalid object name 'HFC_Epay.dbo.Epay_Traction_Table'

    where does it go wrong? here is my code:

    Thank you.

    ----------------------------------------------------------

    SELECT     T.EmployID, T.Batch_Num, U.LASTNAME, U.FRSTNAME

    FROM         HFC_Epay.dbo.EPay_Transaction_Table T INNER JOIN

                          HFC.dbo.UPR00100 U ON T.EmployID = U.EMPLOYID

    WHERE     (T.Batch_Num =

                              (SELECT  MAX(batch_num)

                                 FROM   HFC_Epay.dbo.Epay_Traction_Table))

     

  • try this...

    SELECT T.EmployID, T.Batch_Num, U.LASTNAME, U.FRSTNAME

    FROM HFC_Epay.dbo.EPay_Transaction_Table T INNER JOIN

    HFC.dbo.UPR00100 U ON T.EmployID = U.EMPLOYID

    WHERE (T.Batch_Num =

    (SELECT MAX(HFC_Epay.dbo.Epay_Traction_Table.batch_num)

    FROM HFC_Epay.dbo.Epay_Traction_Table))

  • Could it be that you meant to spell Traction as Transaction in the final FROM clause ?

  • No Its Transaction i believe...... Just one changes ... MAX(HFC_Epay.dbo.Epay_Traction_Table.batch_num) instead of  MAX(batch_num)

  • Are you sure dbo is the owner of the table.

    I would open enterprise manager and confirm dbo owns the tables.  I have worked on some systems that they gave the tables owners other than dbo.

    Let us know.

    Tom

  • if not sure of who the owner is just use

    MAX(HFC_Epay..Epay_Traction_Table.batch_num) instead of  MAX(batch_num).

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

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