SQL query 2 different databases and combine output to file?

 5 Replies
 1 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
Manley
New Member
Posts: 2
New Member

    Hi-

    I need to be able to query a Lawson table, joined to a table in a separate non-Lawson database and output the data to a file.

    With SQL DTS / SSIS this is pretty easy, and is basically a JOIN query using store number in this case.  The results are already in rows, so I just output the query results to a file.

    Has anyone done anything like this with PFI? 

    A simplified example would be:

    Query Lawson EMPLOYEE table for Emp# and Name, JOIN to a separate SQL server and database on Emp# and query CurrentStatus

    Is this possible?

    Thanks!

    David Williams
    Veteran Member
    Posts: 1127
    Veteran Member
      I've done this the other way around - used a SQL Query to get data from an external DB and then a standard Query to check for additional data from Lawson. You just have to build the 2nd query with the first and check one record at a time.
      David Williams
      John Henley
      Posts: 3353
        That is a valid approach. The "join" is done by looping thru one result set and looking, one record at a time, at the other database. So, depending on what you're doing, performance may be an issue. You could probably also take your DTS SQL approach in PFI using a single SQL statement using linked databases.
        Thanks for using the LawsonGuru.com forums!
        John
        Sam Simpson
        Veteran Member
        Posts: 239
        Veteran Member
          As John mentioned, you can use PFI (SQL Query) but I don't know how to link two different databases.

          I use SQR language to query different databases like ORACLE, DB2 or Informix in one single sql.
          John Henley
          Posts: 3353
            "Linked servers" is a function of the database itself, and is definitely part of SQL Server, so it should work for a query thru PFI's SQLQuery node.
            There are 3 steps:
            -- Create linked server reference to Database Engine instance on another machine
            EXEC master.dbo.sp_addlinkedserver @server = N'SERVERNAME\INSTANCENAME', @srvproduct=N'SQL Server'
            GO
            -- Use current login's security context for the link
            EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'SERVERNAME\INSTANCENAME', @rmtuser = N'lawson' , @rmtpassword = N'lawson' , @useself = N'False'
            GO

            -- Run a test query
            SELECT EMP.LAST_NAME, PEM.EMPLOYEE,EMP.EMPLOYEE
            FROM [SERVERNAME\INSTANCENAME].LawProd.lawson.EMPLOYEE EMP
            JOIN [SERVERNAME\INSTANCENAME].LawProd.lawson.PAEMPLOYEE PEM
            ON PEM.COMPANY = EMP.COMPANY
            AND PEM.EMPLOYEE = EMP.EMPLOYEE
            GO
            Thanks for using the LawsonGuru.com forums!
            John
            Manley
            New Member
            Posts: 2
            New Member

              Thanks John!  I will give that a try...

              Manley