2011-01-07 10 views
9

どのように私はこのクエリでは、このクエリによって更新された行を印刷することができます。トン-SQLの出力

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

どのバージョンのSQL Serverを使用していますか? – Oded

+0

SQL Server 2008 – PhilBrown

答えて

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 
+0

これはそれですが、OUTPUTはSETに入ります。私はINSERTEDがTable1.RecommendationLegであることに気付くまで問題を抱えていました。 "OUTPUT INSERTED.actualValue as av、inserted.actualPrice as ap、str.currentSize as cs"のようにすることができます。 – PhilBrown

+3

mullet btwが大好きです。 – PhilBrown

3

あなたはSQL Server 2005と上記にある場合、あなたはOUTPUT clauseを使用することができます。