The OPENQUERY function executes a pass-through query on the given linked server, which is an OLE DB data source. This function can be referenced in the FROM clause of a query as though it is a table name. The OPENQUERY function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, the OPENQUERY functions returns only the first one.
The limitation here is that you can only pass less than 8000 characters as your pass-through query with the OPENQUERY function.
Steps to Reproduce Behavior
- Create a linked server through the SQL Enterprise Manager or by using the sp_addlinkedserver and sp_addlinkedsrvlogin stored procedures.
- Try to run a long SQL statement (more than 8000 characters) from the SQL Server Query Analyzer. You can use a query similar to:
SELECT * from OPENQUERY(YourLinkedServer, 'Select au_lname, au_lname, au_lname, ..... au_lname, au_lname from dbo.Authors')
In the preceding code example you can repeat the column name (au_lname) enough times to create a query that is greater than 8000 characters.
You can reproduce this problem by using any client that can execute SQL statements against SQL Server, including the SQL Server Query Analyzer as well as ODBC, OLE DB, and ActiveX Data Objects (ADO) applications.