t-sql输出更新的结果

时间:2011-01-07 17:46:35

标签: sql-server-2008 tsql

如何在此查询中打印此查询更新的行:

update
    Table1.RecommendationLeg 
set 
    actualValue = ( leg.actualprice * str.currentSize)
from
    Table1.RecommendationLeg leg  
    inner join Recommendation str 
        on leg.partofId = str.id
where 
    leg.actualValue = 0 
    and datediff( n, timeOf, CURRENT_TIMESTAMP) > 30

2 个答案:

答案 0 :(得分:10)

update
    Table1.RecommendationLeg 
set 
    actualValue = ( leg.actualprice * str.currentSize)
OUTPUT INSERTED.actualValue -- <-- this. Edit, after SET not UPDATE. Oops. Sorry.
from
    Table1.RecommendationLeg leg  
    inner join Recommendation str 
        on leg.partofId = str.id
where 
    leg.actualValue = 0 
    and datediff( n, timeOf, CURRENT_TIMESTAMP) > 30

答案 1 :(得分:3)

如果您使用的是SQL Server 2005及更高版本,则可以使用OUTPUT clause