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
 I hate joins

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-04-13 : 11:17:10
alot.

I have two tables: Civil.dbo.receipts and civil.dbo.gcsoreceipts. I need to update the values in the CLERK column in civil.dbo.receipts with the value in the gcsoreceipts table. The identifying column which both tables have in common is the receiptno field. I'm assuming it's a join that will bring peace to my world. Please help me understand how that would look.

thanks

james

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-04-13 : 11:24:32
It should be fairly easy, but please help us to help you. Pease post DDL, DML and expected output. The following links will help you prepare that for us in a consumable format.

http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-13 : 11:25:29
Something like this? Hard to say without seeing the table DDLs. In any case, uncomment the two lines I have commented out and run the select part to see what is going to be updated before you use it if you choose to use it.
UPDATE r SET
r.CLERK = g.CLERK
--SELECT
-- r.CLERK,g.CLERK
FROM
Civil.dbo.receipts r
INNER JOIN civil.dbo.gcsoreceipts g ON
g.receiptno = r.receiptno;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-13 : 11:30:13
first question is how tables Civil.dbo.receipts and civil.dbo.gcsoreceipts are related. is relation 1:1 or 1:n. If latter how do you want update to happen? is it somekind of rollup (aggregation) or do you want one specific occurance value to be updated for each receiptno ?

As suggested by others, posting some data should give us more idea

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

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-04-13 : 11:37:49
looking more closely at this now. may be more than i thought it to be. will be back. thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-13 : 11:43:47
no problem. take your time

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

Go to Top of Page
   

- Advertisement -