[英]How to Use OpenQuery to do Create Alias (IBM DB2) in SQL Server
I use linked server to connect AS400 DB2.我使用链接服务器连接AS400 DB2。
For example: select query can work例如:select 查询可以工作
select *
from openquery([DB2], 'select t1.* from lib.table01 t1
fetch first 1 rows only')
But I want to use query但我想使用查询
Create Alias Library.T_temp For Library.T1 (MemberName)
in SQL Server.在 SQL 服务器中。
It returned an error because it have no return rows.它返回了一个错误,因为它没有返回行。
As following (it will return error):如下(它会返回错误):
Select * from OpenQuery([DB2],' Create Alias...')
Update OpenQuery([DB2],' Create Alias...')
Is there any method to do that?有什么方法可以做到吗?
Thanks谢谢
Don't try..不要尝试..
Your openquery()
is the preferred solution.您的
openquery()
是首选解决方案。
By using openquery()
, the SQL statement is passed to Db2 and run there.通过使用
openquery()
, SQL 语句被传递给 Db2 并在那里运行。 Since you've included a fetch first 1 rows only
only 1 row is returned.由于您已包含
fetch first 1 rows only
返回 1 行。
the query form查询表格
select TOP 1 t1.*
from db2.myibmi.lib.table01 t1
offset 0 rows
first first 1 row only
Will actually pull back all rows to SQL Server, then filter them on the SQL Server.实际上会将所有行拉回 SQL 服务器,然后在 SQL 服务器上过滤它们。 (At least I know that's how it used when a
WHERE
clause was included. I assume TOP
isn't any better) (至少我知道在包含
WHERE
子句时它是如何使用的。我认为TOP
并没有更好)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.