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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problem While Updating

Author  Topic 

ismail_issac
Starting Member

22 Posts

Posted - 2005-11-26 : 08:37:15
Hi
I want to update the data of perticular rows in a table to the other rows in the same table.

My querry is

Update Tab1 Set Tab1.Col1 = Tab2.Col1 , Tab1.Col2 = Tab2.Col2 from Table1 as Tab1 , Table2 as Tab2 where Tab1.Rows = 1 and Tab2.Rows = 2 and Tab1.Cols = Tab2.Cols

Rows Col1 , Col2 , Cols
1 30 40 A
1 10 20 B
2 16 10 A
2 5 8 B

I want to update Above table with data of Rows = 1 with the values of Rows = 2

so out put should be

Rows Col1 , Col2 , Cols
1 16 10 A
1 5 8 B
2 16 10 A
2 5 8 B


The querry is not updating the required record. Any Suggestions

Thanks In Advance

Kristen
Test

22859 Posts

Posted - 2005-11-26 : 09:15:59
Looks OK to me, except that I would have used a JOIN.

Also you are referings both "Table1" and "Table2" but you indicate that the data is all in one table

Update Tab1
Set Tab1.Col1 = Tab2.Col1,
Tab1.Col2 = Tab2.Col2
from Table1 as Tab1
JOIN Table2 as Tab2 -- Should be Table1 ??
ON Tab2.Rows = 2
AND Tab2.Cols = Tab1.Cols
where Tab1.Rows = 1

Kristen
Go to Top of Page

ismail_issac
Starting Member

22 Posts

Posted - 2005-11-26 : 09:45:14
oh yes... sorry for the mistake. it should be Table1
Go to Top of Page
   

- Advertisement -