SQL and Progress for linked server

Jinal Contractor 121 Reputation points
2022-04-06T16:04:44.787+00:00

Right now, we have a Linked Server set up from the production SQL server called SQL4 to the kproduction Progress Database. Linked servers have some limitations, or maybe I haven’t found the right solution. I can’t pass in a dynamic variable into the OpenQuery script. So, if I want to pull a list of orders shipped yesterday from the kproduction Progress Database, I have to hard code the “yesterday” part of the query.

Is a Linked Server the only option here? Is there a better solution to enable us to pull data from both systems?

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bert Zhou-msft 3,436 Reputation points
    2022-04-07T02:12:56.53+00:00

    Hi,@kkran

    Welcome to Microsoft T-SQL Q&A Forum!

    Maybe you have seen the official documentation, OPENQUERY will not accept variables, maybe you can use a temporary table, extract data from the table into local variables,
    or use dynamic queries, which are also written in the sql series of books, please refer to Link.
    For the link between the progress database and the current sql, please refer to this document.

    Best regards,
    Bert Zhou


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Naomi Nosonovsky 8,431 Reputation points
    2022-04-06T16:26:14.337+00:00

    You can prepare the whole query (all statement) as a sql string (including OpenQuery) and then execute using sp_executeSQL procedure.


  3. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-04-06T21:51:19.46+00:00

    You can run four-part queries:

       SELECT * FROM SERVER.db.schema.tbl WHERE OrderDate > @date  
    

    But there may be limitations that prevents this from working with Progress.

    EXEC AT supports parameters:

       EXEC('SELECT * FROM Orders WHERE OrderDate > ?', [@](/users/na/?userId=19179bf8-7ffe-0003-0000-000000000000)) AT PROGRESS  
    

    With OPENQUERY you need to build a query string dynamically. Which certainly is not any fun.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.