Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2007-02-05 : 12:28:59
|
| I need help in optimizing this query. The major time takes in calling a remote database. Thanks in advance.ALTER PROCEDURE dbo.myAccountGetCallLogsTest@directorynumber as varchar(10),@CallType as tinyintASdeclare @dt as intSELECT TOP 1 @dt=datediff(day,C.EstablishDate,getdate())FROM ALBHM01CGSERVER.Core.dbo.Customer C INNER JOIN ALBHM01CGSERVER.Core.dbo.UsgSvc U ON C.CustID = U.CustIDWHERE (U.ServiceNumber = @directoryNumber)ORDER BY C.EstablishDate DESCIF @dt>90select DN as Number, Remote_DN as [Remote Number], City, StartTime as [Start Time], EndTime as [End Time]from vw_Call_Logswhere DN = '1' + @directoryNumber and call_type = @CallType and datediff(day,starttime,getdate())<90order by starttime descELSEselect DN as Number, Remote_DN as [Remote Number], City, StartTime as [Start Time], EndTime as [End Time]from vw_Call_Logswhere DN = '1' + @directoryNumber and call_type = @CallType and datediff(day,starttime,getdate())< @dtorder by starttime desc |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-02-05 : 12:36:51
|
| Have a look at the query placn and see what it is sending to the remote database.maybe something likedeclare @sql nvarchar(4000)select @sql = 'SELECT TOP 1 @dt=datediff(day,C.EstablishDate,getdate())FROM Customer C INNER JOINUsgSvc U ON C.CustID = U.CustIDWHERE (U.ServiceNumber = ''' + @directoryNumber + ''')ORDER BY C.EstablishDate DESC'exec ALBHM01CGSERVER.Core.dbo.sp_executesql @sql, N'@dt int out', @dt out==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2007-02-05 : 13:00:33
|
| I get Remote scan cost = 100% |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-02-05 : 13:15:41
|
| It should show you the query that is being sent to the remote server. It may be transfering all the data locally. The query I gave above should cure that if you can run it.If not check the link server compatibility settings.Better is to call a stored procedure on the remote server to return the data.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2007-02-05 : 16:42:13
|
| Thanks, I created a stored procedure on the remote server and it works in a split second. |
 |
|
|
|
|
|
|
|