SQL Update Statement Using 2 Tables

I am attempting to update two tables.  I have a parent table and child table, and when updating the parent table I also want information in the child table to be updated as well, but I cannot seem to get the update statement to work as expected.

What I am attempting here is when updating the parent table to also update the ttblSalesAppt table column txtAppts.

I already have a select statement where the information is pulling correctly from the ttblSalesAppt table, but at this point I am having to update that table seperatly in order for the select statement to show up correctly.

I hope I have provided enough information regarding this issue.

Would it be smarter to attempt a stored procedure for this also, I have never written one, but have read where this could be used for this situation.

UPDATE    tblSalesManifestGAA
SET              txtLocation = @txtLocation, dtDate = @dtDate, dtPartyTime = @dtPartyTime, txtLNameGuest = @txtLNameGuest, txtFNameGuest = @txtFNameGuest, 
                      txtProgCode = @txtProgCode, txtMktgComment = @txtMktgComment, txtBooker = @txtBooker, txtComments = @txtComments, ckShow = @ckShow, 
                      ckNoShow = @ckNoShow
FROM         tblSalesManifestGAA INNER JOIN
                      ttblSalesAppt ON tblSalesManifestGAA.pkSalesManGAAID = ttblSalesAppt.pkSalesManGAAID
WHERE     (tblSalesManifestGAA.pkSalesManGAAID = @pkSalesManGAAID)

Open in new window

ViewUpdate.bmp
daleimiAsked:
Who is Participating?
 
reb73Connect With a Mentor Commented:
Yes, two update statements preferably within a transaction like -

BEGIN TRAN ...
Update Table1...
Update Table2...
COMMIT

This way the parent/child tables should be in sync..
0
 
BrandonGalderisiCommented:
You cannot update two tables with one statement.  You would have to use two separate statements.  
0
 
daleimiAuthor Commented:
Okay so how would this be accomplished using just a Cross Join, and updating each table as a seperate entity seperated by a " ; " or just two statements seperate within the builder such as:

Update tableA
Set       txtsomething=@txtsomething
From    tableA
Where txtsomething=@txtsomething

Update tableB
Set txtsomethingb=@txtsomethingb
From tableB
Where txtsomethingb=@txtsomethingb

Am I on the right track here, or completely off?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
BrandonGalderisiCommented:
That's not a cross join.  A cross join is a join whereby every record from one table is joined with every record from another.  Thus producing a cartesian.

Yes, two update statements.
0
 
yatin_81Commented:
Instead of writing any code to update the column in other table, if you want to store same value in column of other table, then it would be recommended to use relationship between two table.
What you can do is make a relationship between two tables and set cascade update. The child table will be automaitically updated when the value in parent table changes.
0
 
daleimiAuthor Commented:
Yeah that is a new concept for me, have not been working with SQL for very long, I am still trying to figure out the relationship of Primary key to Foreign key.

Are there any sites you can direct me to in order to accomplish this task.

Any help would be appreciated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.