Dynamic SQL query from Linked Server

hhnetworks
hhnetworks used Ask the Experts™
on
I have a query that Im running against a linked server. Due to the 8000 character limit of Openquery, I am using dynamic SQL:
DECLARE @SQL1 VARCHAR(MAX)
SET @SQL1 = '<huge select query>'
EXECUTE (@SQL1) AT LinkedServer

Open in new window

How do I "SELECT * INTO <Table>" on my local server?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Developer
Commented:
You can't. You can use the INSERT INTO .. EXECUTE statement instead.

BUT: review your use-case. Create a procedure on the remote server to handle what you need.

Author

Commented:
Thanks!  I only have Read Only access to the remote server, so cant use an SP on it.  The INSERT INTO is working.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial