Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Dynamic SQL in linkedserver.

 
   Database Forums (Home) -> Clustering RSS
Next:  What does everyone else do for graphically displa..  
Author Message
Shiju Samuel

External


Since: Dec 10, 2007
Posts: 6



(Msg. 1) Posted: Tue Dec 11, 2007 6:34 am
Post subject: Dynamic SQL in linkedserver.
Archived from groups: microsoft>public>sqlserver>clustering (more info?)

I have a statement in the sp which does something like this.

@sql = 'SELECT OrderDate,CustID,Total,Balance from '
+ @Remoteserver
+ '.dbo.Sales.Orders where orderid =' + @orderid

exec(@sql)


The issues, which I can think with dynamic SQL, are

1. Excessive compilation of statements.
2. Due to unused compiled plan Data cache can be offloaded out of the
memory.
3. Context changes to connection login. (I am not sure if this is
expensive..is it?)
4. Ownership chaining doesn't work and need an explicit permission on
objects.

I can think of two approach to make this statement more efficient.
A] Approach 1st
1. Get all the possible values passed to @Remoteserver from the app team.
2. Create a static sp's in all the servers which takes @orderid as
parameter to select the orders table.
3. In the local server create multiple if statements to call a particular
SP.

I am sure I can eliminate the 1st and 2nd issue of dynamic query with
this. I am not sure if the 3rd and 4th issue mentioned is relevent here
when the server has to create a context to login to the remote server.


B] Approach second.
1. Use sp_executesql to parameterize the @orderid parameter. and let the
@servername parameter be part of @sql string.

I am wondering which approach is good.


-
Thanks
Shiju Samuel

 >> Stay informed about: Dynamic SQL in linkedserver. 
Back to top
Login to vote
Shiju Samuel

External


Since: Dec 10, 2007
Posts: 6



(Msg. 2) Posted: Tue Dec 11, 2007 6:54 am
Post subject: Re: Dynamic SQL in linkedserver. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Apologies upfront. I just realized I have posted it in the wrong group.

Please ignore.

-Shiju Samuel

 >> Stay informed about: Dynamic SQL in linkedserver. 
Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> Clustering All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]