Solved

Modify SQL Stored Procedure to use OPENQUERY

Posted on 2013-05-20
1
478 Views
Last Modified: 2013-05-20
I have a SP that no longer works with the remote DB2 database after a updated. I have found that I can query the SQL linked server with OPENQUERY and not simple select statements. Can anyone assist in how this SP can be modified to work with OPENQUERY?

UPDATE ap_invoice SET Check_Number = v.CHECK_NUMBER, Check_Date = v.CHECK_DATE
      from ap_invoice i
      inner join LINKEDSERVER.database.schema.table v on i.INVOICEKEY = v.INVOICEKEY
      where i.Check_Number = '0'


for reference here are my test select statements...

select * from OPENQUERY (LINKEDSERVER, 'select * from schema.table')   --- This works fine

Select * from LINKEDSERVER.database.schema.table    -- this returns "OLE DB provider "MSDASQL" for linked server "LINKEDSERVER" returned message "[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0204 - SYSCOLUMNS in QSYS2 type *FILE not found.".
0
Comment
Question by:acconsultant
1 Comment
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 39182779
;with cte_oq as (select * from OPENQUERY (LINKEDSERVER, 'select * from schema.table'))

UPDATE ap_invoice SET Check_Number = v.CHECK_NUMBER, Check_Date = v.CHECK_DATE
      from ap_invoice i
      inner join cte_oq v on i.INVOICEKEY = v.INVOICEKEY
      where i.Check_Number = '0'
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Query To Insert One Year Calendar 6 44
Insert Salary Period that has 2 months 11 22
SQL Server - SQL field is defined as text 3 27
TSQL previous 5 23
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now