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 2005 Forums
 Transact-SQL (2005)
 Updating table

Author  Topic 

Ali T
Starting Member

22 Posts

Posted - 2008-11-26 : 10:47:22
Dear all
I have a table called "Trans" two columns called ID and A.
I have another table called "R" with two columns called "ID" and "B".
the IDs are the same.
I want to write a query which checks the content of each cell of Column A from table "Trans" and then if the number in it is more than 0 update The corresponding cell ofColumn "B" in table " R" with "1".
I'd appreciate it if you help me with this matter.

Regards

Ali

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-26 : 12:02:08
just a simple join will do

UPDATE r
SET r.B=CASE WHEN t.A>0 THEN 1 ELSE 0 END
FROM R r
JOIN Trans t
ON t.ID=r.ID
Go to Top of Page

Ali T
Starting Member

22 Posts

Posted - 2008-11-26 : 16:39:43
Dear visakh16
Problem solved. I'm Really thankful!

Ali
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-27 : 04:09:46
welcome
Go to Top of Page
   

- Advertisement -