x
login about faq Site discussion (meta-askssc)

Slow query due to variable

Hello everyone,

this query is driving me crazy The problem is that when I'm in a server and execute a query against another server, it works well when I use hardcoded values but turns terrible slow when I use a variable. I've looked everywhere but haven't got the right answer. This problem exist in queries and Stored Procedures. I've tried this with parameters instead of variables and the problem persists.

The weird thing is that two days ago I was able to execute the query qith the variable without problems.

Any insight will be welcome

Thanks

USE DataBaseInServerA

Declare @date smalldatetime
Set @date = ‘1987-03-15’
Select * from ServerB.asd.dbo.person
Where birthday = '1987-03-15' --- < This works perfectly

Select * from ServerB.asd.dbo.person
Where birthday = @date --- < This takes toooo long
more ▼

asked Dec 17 '09 at 08:45 PM in Default

Jose Mayorga gravatar image

Jose Mayorga
61 1 1 1

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Now it works fine. The problem was an option in the server.

Under this path:

Server Objects - Providers - SQLOLEDB

I activated the 'Dynamic parameters' option and that was it! silly, uh?

The problem was that the ServerB was sending the whole table and ServerA was applying the filter instead of pasing the parameter value so the ServerB could apply the filter

more ▼

answered Dec 17 '09 at 09:04 PM

Jose Mayorga gravatar image

Jose Mayorga
61 1 1 1

Yup, that'd do it. Good that you asked (and answered), because it will hopefully help someone else who has the same problem with their linked servers. Make sure you mark it as the accepted answer.

Dec 17 '09 at 11:45 PM Rob Farley
(comments are locked)
10|1200 characters needed characters left

i couldnt find the place to change the settings. :/

more ▼

answered Mar 10 '10 at 06:06 AM

Murat gravatar image

Murat
1

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x916
x322

asked: Dec 17 '09 at 08:45 PM

Seen: 1254 times

Last Updated: Dec 18 '09 at 10:33 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.