我有两张桌子,其中一张我不再需要了。我想将我需要的数据从过时的表中转移到我要保留的表中。两个表中都有bookingid
列,我可以用它们来匹配行。它是 1 对 0 或 1 的关系。我环顾四周并建立了这个查询来完成传输,但我得到了一个无法绑定的错误bookingtoupdate.bookingid
WITH bookingtoupdate (bookingid) AS
(
SELECT bookingid
FROM bookings
)
UPDATE bookings
SET meetinglocation = (SELECT business.name
FROM abk_Locations
INNER JOIN business ON dbo.abk_Locations.IP_Number = business.businessid
WHERE
(dbo.abk_Locations.Booking_Number = bookingtoupdate.bookingid)
)
WHERE
bookingid = bookingtoupdate.bookingid
我的代码有什么明显的问题吗?
我参考了以下页面...
http://msdn.microsoft.com/en-us/library/ms175972.aspx SQL Server FOR EACH 循环