November 28, 2010 at 1:06 am
What do want to do with the rows in your c.u.r.s.o.r.?
Most likely there is a solution where you don't need that kind of a loop at all.
An index on "almost every column" will only help, if there is one index starting with the [Date] column.
But as I said before: most likely you don't need it at all.
If you'd like to see a set-based solution, please provide table def and some sample data to play with together with your expected result and the business rules on how to get there. If the c.u.r.s.o.r. code is less than 200 lines, include that as well.
Regarding the best way to post sample data please read and follow the first link in my signature.
November 28, 2010 at 4:20 am
I agree, more often than not cursors are the wrong approach to take when dealing with data.
Just so you can figure out what's happening though, elminate the cursor from the equation, run just the select statement and get the execution plan. See how long that takes and what the query is doing. That might offer a solution immediately. If not, you might have to start looking elsewhere, possibly your tempdb is under stress or something else. But I'd start with the query.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 28, 2010 at 9:32 am
Is it the cursor or the join? How long does it take to run the following?
Select [Cmp],[App],[Cmd],[MsgID],[uid],[Date],[Sr],[Ct],[Rec],[E1],[Pr],[OP],[FDate],[R1],[U1],[CP],[Or],[udi2],[Se],[Se1],[Sp],[Cy],[Mt],[Ce],[Ida1],tblRec.Value
From TempTable
INNER JOIN tblRec ON TempTable.Rec = tblRec.Id
Order By [Date] ASC
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply