Sql-server – Query DB2 without using Openquery

db2sql-server-2008-r2

Is there a way to query a DB2 Linked Server without using Openquery? IE, is it possible to query DB2 through a linked server by doing something like the following?

select *
from [db2_linked_server].[database].[tablename]

Best Answer

Assuming your linked server provider supports it, you should be able to use a 4-part name (your example only used 3-parts)

I'm referencing Transact-SQL Syntax Conventions-Transact-SQL.

server_name .[database_name].[schema_name].object_name

WHERE

server_name Specifies a linked server name or remote server name.

database_name Specifies the name of a SQL Server database when the object resides in a local instance of SQL Server. When the object is in a linked server, database_name specifies an OLE DB catalog.

schema_name Specifies the name of the schema that contains the object if the object is in a SQL Server database. When the object is in a linked server, schema_name specifies an OLE DB schema name.

object_name Refers to the name of the object.