Solved

Modify SQL Stored Procedure to use OPENQUERY

Posted on 2013-05-20
1
480 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Solution for warm standby SQL server 20 49
MS SQL Server - Looking to filter rows based on column value 3 37
SQL Help 27 45
While in ##Table - Help 4 16
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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