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
 Help with a VERY slow query please .

Author  Topic 

alexellice
Starting Member

13 Posts

Posted - 2012-12-19 : 09:34:09
[code]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'[/code]

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

52326 Posts

Posted - 2012-12-19 : 09:43:05
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 - 2012-12-19 : 09:53:18
ok, sorry
Go to Top of Page
   

- Advertisement -