Article ID: 222937 - Last Review: December 4, 2007 - Revision: 3.2 Creating a linked server to DB2 using Microsoft OLE DB provider for DB2This article was previously published under Q222937 On This PageSUMMARY
This article provides a sample SQL script for creating a linked server to DB2 using sp_addlinkedserver, and issues a few queries to illustrate the Distributed Query Processing (DQP) using DB2OLEDB, the Microsoft OLE DB provider for DB2. Please refer to the following article in the Microsoft Knowledge Base for information on the keywords used in the DB2OLEDB initstring.
218590
(http://support.microsoft.com/kb/218590/
)
Configuring data sources for the Microsoft OLE DB provider for DB2
Creating Linked Server
Sample Distributed QueriesExample of SELECT using 4-part name: LinkedServer.Catalog.Schema.TableSELECT * FROM WNW3XX.OLYMPIA.WNW3XX.DEPARTMENT Example of Pass Through SELECT using OPENQUERY with 3-part name: SELECT * FROM OPENQUERY(WNW3XX,"SELECT * FROM OLYMPIA.WNW3XX.EMP_ACT") Example of Pass Through SELECT using OPENROWSET with 2-part name: SELECT * FROM OPENROWSET ('DB2OLEDB',Netlib=SNA;NetAddr=;NetPort=;RemoteLU=OLYMPIA;LocalLU=LOCAL;ModeName=QPCSUPP;User ID=WNW3XX;Password=WNW3XX;InitCat=OLYMPIA;Default Schema=WNW3XX;PkgCol=WNW3XX;TPName=;Commit=YES;IsoLvl=NC;AccMode=;CCSID=37;PCCodePage=1252;BinAsChar=NO;Data Source=Sample', 'SELECT * FROM WNW3XX.EMPLOYEE' ) Example of an INSERT using 4-part name: INSERT INTO WNW3XX.OLYMPIA.WNW3XX.DEPARTMENT VALUES ('E21','DUMMY',NULL,'E01') Note that UPDATE and DELETE using DQP are not possible with the DB2OLEDB provider that shipped with SNA version 4.0 Service Pack 2 and Service Pack 3 due to lack of bookmark support, but these do work with the SNA 4.0 Service Pack 4 provider and the provider that shipped with Host Integration Server. For more information on this, see the following article in the Microsoft Knowledge Base: 287093
(http://support.microsoft.com/kb/287093/EN-US/
)
DB2OLEDB Supports UPDATE/DELETE from SQL Linked Server
Example of JOIN between a SQLServer and DB2 table: SELECT A.EMPLOYEE_NUMBER,B.ACTNO FROM CORPDATA..EMPLOYEE_ACCOUNT A, WNW3XX.OLYMPIA.WNW3XX.EMP_ACT B WHERE A.EMPLOYEE_NUMBER = B.EMPNO ORDER BY A.EMPLOYEE_NUMBER | Article Translations
|
Back to the top
