
Saturday, December 17, 2005
Update و Join با هم
Update a field in a table using a value from another table where both records are referenced by a common key - warning, different databases support different syntax!
This works in MS-Access but not in SQL Server:
update TableOne
inner join TableTwo on TableOne.commonID = TableTwo.commonID
set TableOne.field1 = TableTwo.fieldXor
This works in MS-Access but not in SQL Server:
update TableOne, TableTwo
set TableOne.field1 = TableTwo.fieldX
where TableOne.commonID = TableTwo.commonID
or
This works in SQL Server but not in MS-Access (my thanks to John Lee for this):
update tableOne
set tableOne.field1=tableTwo.fieldX
from tableOne, tableTwo
where tableOne.commonID=tableTwo.commonID
اين Post را مریم در زمان
6:17 AM ارسال كرده
نظرات ديگران
-
وب سايت علمی/فنی
©تمامي حقوق اين سايت براي مولف محفوظ مي باشد
یه کمی بیشتر توضیح میدادی بیشتر متوجه میشدیم...
Actually the following code is more efficient than the code that you are suggesting for SQL Server (because of SQL Server's enhasment ways to calulate join statements)
UPDATE tableOne
SET tableOne.field1=tableTwo.fieldX
FROM tableOne
INNER JOIN tableTwo
ON tableOne.commonID = tableTwo.commonID
good luck :)