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

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-01-30 : 05:23:45
I have a 'one' table (tblRequests) linked to a 'many' table (tblRequestDetails)by field MovementId.

There is a field in each called Dept. In the one table this has a value, but the value is not in the many table. How can I write an update query that will put the value from Dept in the one table into the field Dept in the many table.

Due to a bug in my program it was not updating the many table with this value.

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-30 : 05:31:49
If the value is already in the tblRequests, why do you want to duplicate it in the tblRequestDetails table? You can get the value just by joining tblRequests with tblRequestDetails anytime you want.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-01-30 : 05:33:53
I was going to run queries to sum and count by dept and thought it easier to do it on one table. Just thought it was tidier....
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-30 : 05:43:24
[code]Update RD
set Dept = R.Dept
from tblRequestDetails as RD
JOIN tblRequests as R
on RD.MovementId = R.MovementId[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-01-30 : 10:33:05
Many thanks
Go to Top of Page
   

- Advertisement -