January 5, 2009 at 4:43 am
Hi All,
Can anyone help be to find possibilities of updating two tables using single UPDATE statement in SQL 2000?
Is it possible?
Best Regards
Boney
January 5, 2009 at 5:24 am
not possible with a single sql statement.... each table updated gets its own UPDATE statement, but it's not hard to put them together as a transaction. both tables can be updated from some table or the results of a join of other tables.
In the future, try to provide more details...what you tried so far, table structure, sample data.
with no table structure provided and no definitions, here's a crappy example to get the thoughts flowing:
[font="Courier New"]
SET XACT_ABORT ON
BEGIN TRAN
--first table
UPDATE TABLE1
SET TABLE1.SOMEVALUE = THIRDTABLE.SOMEVALUE
FROM THIRDTABLE
WHERE TABLE1.PK = THIRDTABLE.PK
--second table
UPDATE TABLE2
SET TABLE2.SOMEVALUE = THIRDTABLE.SOMEVALUE,
AUDITDT=GETDATE()
FROM THIRDTABLE
WHERE TABLE2.PK = THIRDTABLE.PK
COMMIT TRAN
[/font]
Lowell
January 5, 2009 at 6:45 am
Why do you need it to be in a single statement?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply