views:

212

answers:

4

I have a scheduled AM process on SQL Server 2008 that imports data from Oracle using a linked server. I am overwriting the imported data from Oracle using drop table, then select into pattern

Apparently, the presence of the "order by" affects my end result! Take a look.

--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

But this (below) returns no rows. My orgId of 1000107 is now missing?

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

As you can see the only thing changed is the presence of the order by clause. Another tidbit is that the linked server query is returning same rowcount (51,225 rows to be exact) whether or not the "order by" exists. Any ideas?

A: 

May be you need recalculate indexes on Oracle?

Alexey Sviridov
A: 

Is there an option like SET ROWCOUNT in effect? In particular on the linked Oracle database. It's been years since I've done anything with Oracle so I don't remember their particulars.

DaveE
A: 

Seems that I'm running into some sort of cap at 51,225 rows. I do not control the Oracle side, another dept at my org does. One of their people say that exact query is supposed to return 51,324 rows.

So, what's really happening is that I'm 99 rows short of the full result set. My "order by" clause re-prioritizes the results, and happened to give me the one row I was looking for. Unfortunately of course, it's still bumping 99 other results out!

I don't know what is significant about the 51,225 number. Hard for me to imagine that the sql server config of the linked server would have that set somehow (I just went with defaults when setting it up).

Worse case, I'll just split the import into 2 queries, ordered oppositely so I cover all the bases. I really need to get to the bottom of that mysterious 51,225 "cap" though...

Thanks much for all the input!

A: 

Linked server based on Provider: "Oracle Provider for OLE DB" (instead of based on a local System ODBC connection "Microsoft OLE DB Provider for ODBC Drivers") returned the full result set first try.

For some reason, there must be a lower ceiling on the ODBC connection regarding maximum rows that can be returned. Only setting I found was "fetch buffer size," I tried doubling, still same amount of rows returned.

For this query, I'll just use the other linked server.

Thanks again to all for the input!