2011-01-07 7 views
9

cómo se puede imprimir las filas actualizadas por esta consulta en esta consulta:T-SQL de salida de resultados actualizados

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

¿En qué versión de SQL Server estás? – Oded

+0

SQL Server 2008 – PhilBrown

Respuesta

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

Esto es, pero la SALIDA va en el SET. Estaba teniendo problemas hasta que me di cuenta de que INSERTED era Table1.RecommendationLeg. Puede hacer cosas como "OUTPUT INSERTED.actualValue como av, inserted.actualPrice como ap, str.currentSize como cs" – PhilBrown

+3

Love the mullet por cierto. – PhilBrown

3

Si usted está en SQL Server 2005 y anteriormente, se puede utilizar el OUTPUT clause.

Cuestiones relacionadas