SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with a VERY slow query please .
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

alexellice
Starting Member

13 Posts

Posted - 12/19/2012 :  09:34:09  Show Profile  Reply with Quote
UPDATE "Schema" SET varLid = 'S'

FROM
(SELECT pNumber, productName, varLid, MAX(dato) FROM "Schema"
WITH (index (SepOldTempIndex))
WHERE varLid = 'T'
GROUP BY pNumber, productName, varLid HAVING MAX(dato) <= '20010101') AS myData

WHERE myData.varLid = 'T'


The DB "Schema" can have more than 1,000,000 records,
We are using pervasive SQL.
All fields (varLid, pNumber, productName etc are strings)

Running the query "as is" means that it updates all records (not just within the select) in under 6 minutes.. (its only going to be run once). Adding more conditions ie: AND Schema.pNumber = myData.pNumber makes it run extrememly slow.

I need it to update only within the select. I can't using an alias on the UPDATE (pervasive won't allow it). Finaly.. just to make this even more interesting... the DB is VERY old and does NOT have any unique identifiers.

I would be MOST grateful with any suggestions.

Thankyou in advance.

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/19/2012 :  09:43:05  Show Profile  Reply with Quote
please post in relevant forums. This forum is for MS SQL Server and we deal with only t-sql. please try your luck at www.dbforums.com

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

alexellice
Starting Member

13 Posts

Posted - 12/19/2012 :  09:53:18  Show Profile  Reply with Quote
ok, sorry
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000