开发者

Convert Select with Join to Update

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜