I am using T-SQL query directly in Microsoft SQL Server Studio's Query window against to a large Oracle DB, and my SQL server is 2005.
I have created a linked server as myOracleServer. By using the following T-SQL query:
SELECT COUNT(*) FROM myOracleServer..owner.myTable WHERE id = 1000 AND Dt = '2009-02-26'
It take more than 1 minute to make just one call. For a small size table it is OK, but myTable on Oracle side is very large with millions of rows data.
What I found out is that I could use OPENQUERY to make a similar call with SQL query as a pass-through one. The result is very fast. The execution time is 00:00:02!
SELECT * FROM OPENQUERY(myOracleServer, 'SELECT COUNT(*) FROM owner.myTable WHERE ...');
The problem I have is that the query is not a constant string. I may change id and Dt values in the query, something like:
'SELECT COUNT(*) FROM ownwer.myTable WHERE id = ' + CAST(@id AS VARCHAR)...
OPENQUERY does not support a variable as query string nor expression.
Is there any other way to get the pass-through query to Oracle with fast performance?