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
 UPDATE QUERY HELP

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-03-16 : 09:27:07
HI TEAM

I HAVE 3 TABLES TAB1 , TAB2 TAB3

I NEED TO UPDATE TAB1 WITH DATA OF TAB2 AND TAB3 LIKE


UPDATE T1
SET T1.AMOUNT = T2.AMOUNT , T1.TAX = T3.TAX
WHERE T1.ID = T2.ID
AND T1.ID = T3.ID
AND TI.AMOUNT IS NULL OR T1.TAX IS NULL

THERE ARE 50000 RECORDS THAT ARE ELIGLIBLE TO UPDATE, BUT QUERY TAKES TOO MUCH TIME PLEASE HELP.



challenge everything

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-16 : 11:01:27
what are the indexes present on tables? have you had a look at execution plan yet?

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

Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-03-17 : 00:58:02
i have no idea about optimization .

challenge everything
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-03-17 : 05:53:33
[code]UPDATE dbo.T1
SET Amount = (SELECT TOP(1) x.Amount FROM dbo.T2 AS x WHERE x.ID = ID),
Tax = (SELECT TOP(1) x.Tax FROM dbo.T3 AS x WHERE x.ID = ID)
WHERE Amount IS NULL
OR Tax IS NULL[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -