Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I log into a SQL Server database which has an AS400 server as a linked server.

I've discovered that running queries against this AS400 server is MUCH faster if I run the select in an OPENQUERY...

SELECT  EMEQP#
FROM _
WHERE EMALOC = '467' AND EMDLCD = 'A' AND EMSTAT NOT IN ('S', 'J', 'V')

Execution time: 46 seconds

SELECT EMEQP#
FROM
OPENQUERY(_, '
SELECT  EMEQP#
FROM _
WHERE EMALOC = ''467'' AND EMDLCD = ''A'' AND EMSTAT NOT IN (''S'', ''J'', ''V'')
')

Execution time: 1 second

Can someone explain or link me to why/how this is happening?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

When you use openquery the query itself executed on remote server and you receive only results. In case of linked server, you local server does all the job. You may want to check http://social.msdn.microsoft.com/Forums/eu/transactsql/thread/0e68f512-1e19-4c50-b343-219085d70076

share|improve this answer
    
Glad to hear this is totally unrelated to OPNQRYF. –  WarrenT Jan 17 '13 at 17:03
    
Makes sense. Thank you for your answer! –  Theo Jan 17 '13 at 21:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.