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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get performance

Author  Topic 

trento
Starting Member

13 Posts

Posted - 2009-08-10 : 18:20:39
I’m looking into existing daily process in loop like this:
1. Read input seq#,
2. Select into cursor multiple rows from THIST with ORDER
3. Fetch cursor till the end
4. Update THIST.FLAG
5. Commit
6. Close cursor



It’s on SQL 8.0 and it brings some performance issues running very slow, so I’m thinking how I can tune it to run faster. THIST holds data for 10 days, so I’m thinking to work on view VHIST = SELECT * FROM THIST WHERE DATE=today, then I can get rid of ORDER in main select.
And probably get rid of #5 commit.

Not sure how bad update is, anybody can suggest what else Pro’s doing .

Thanks to all.

T

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-08-10 : 19:35:44
Your issue is not clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-08-10 : 22:37:25
I can't begin to imagine why with your cursor solution you go to the end rather than sorting it in descending order and fetching the first one. Anyway, this should do more or less the same depending on the data:

update THIST set flag='value' where date=@today

If you cannot uniquely identify the 'last one' (by using 'today' in the above example) then you need to think again using row_number().

You will need the commit somewhere of course.

Go to Top of Page
   

- Advertisement -