By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,725 Members | 1,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,725 IT Pros & Developers. It's quick & easy.

Open SQL connection using T-SQL

P: 2
I would like to connect to a remote sql server using a stored procedure. I had planned on using OPENQUERY( linked_server ,'query' ) to pull data from the remote server but this command does not accept variables for its arguments. Is there another way to open a connection using Transact-SQL?

Thanks for your help!
Nov 5 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 2,878
Will this work:

Expand|Select|Wrap|Line Numbers
  2. exec ('select * from linked_server.' + @dbname + '.dbo.' + @tablename + ' where blah blah order by blah blah'
That's just a pseudo-code...

Happy Coding!!!

--- CK
Nov 5 '09 #2

P: 2
I guess I just needed to treat it like any other query but include the linked server name in the string.

I'm still pretty wet behind the ears. Thanks so much for your help ck9663. This was my first visit to this sight. I appreciate you taking the time to reply.

- Muddler
Nov 6 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.