开发者

Convert Select with Join to Update

开发者 https://www.devze.com 2023-02-22 08:43 出处:网络
I have a query: SELECT t.*, tb.Upd开发者_如何转开发ateDate FROM #tempBuildings tb INNER JOIN Buildings b ON b.BuildingID = tb.BuildingID

I have a query:

SELECT t.*, tb.Upd开发者_如何转开发ateDate
FROM #tempBuildings tb INNER JOIN Buildings b ON b.BuildingID = tb.BuildingID 
INNER JOIN @tmp t ON t.ID = b.InvestmentId

I know it's hard to understand what is here, but in few words: I have table with buildings, and in #tempBuildings I'm counting date of update.

It's not my idea , but I must add to output one column.

So in temp table @tmp I've added this column , and I must this select query convert to update query foreach row I must do something like:

update @tmp set @tmp.UpdateDate=tb.UpdateDate

I'm sorry for luck of clarity but construction of this queries is incredible.

I'm using sql-server-2005


doesn't this work?

UPDATE t set t.UpdateDate=tb.UpdateDate
FROM #tempBuildings tb 
INNER JOIN Buildings b ON b.BuildingID = tb.BuildingID 
INNER JOIN @tmp t ON t.ID = b.InvestmentId


update t
set t.UpdateDate = tb.UpdateDate
FROM #tempBuildings tb 
INNER JOIN Buildings b ON b.BuildingID = tb.BuildingID 
INNER JOIN @tmp t ON t.ID = b.InvestmentId
0

精彩评论

暂无评论...
验证码 换一张
取 消