我在 SQL Server 2008 上有一个预定的 AM 进程,它使用链接服务器从 Oracle 导入数据。我正在使用 drop table 覆盖从 Oracle 导入的数据,然后选择模式
显然,“order by”的存在影响了我的最终结果!看一看。
--This works fine to give me the one row I'm expecting from the newly imported table:
drop table t1;
SELECT * into t1 fROM OPENQUERY(ODBC_CSRPT,'
select
EXTERNAL_ORGANIZATION_ID
,ORGANIZATION_DESC
,STATE
from sysadm.uv_CS_EXTERNAL_ORGANIZATIONS
order by EXTERNAL_ORGANIZATION_ID asc ');
go
select * from t1
where external_organization_id = '1000107'
go
但这(下)不返回任何行。我的 orgId 1000107 现在不见了?
drop table t1;
SELECT * into t1 fROM OPENQUERY(ODBC_CSRPT,'
select
EXTERNAL_ORGANIZATION_ID
,ORGANIZATION_DESC
,STATE
from sysadm.uv_CS_EXTERNAL_ORGANIZATIONS ');
go
select * from t1
where external_organization_id = '1000107'
go
如您所见,唯一改变的是 order by 子句的存在。另一个花絮是,无论“order by”是否存在,链接服务器查询都返回相同的行数(准确地说是 51,225 行)。有任何想法吗?