将UPDATE语句的OUTPUT定向到局部变量


Answers:


15

不可以,因为您可能会显示OUTPUT多行,而这行将不适合标量变量。

您需要输出到@Table变量或声明的表中以处理多行输出。


是的 即使该电子邮件地址是唯一的,也无法使用可组合的DML和单个分配对其进行黑客入侵SELECT。我收到错误消息,"A nested INSERT, UPDATE, DELETE, or MERGE statement is not allowed in a SELECT statement that is not the immediate source of rows for an INSERT statement."这很不幸,因为当您知道只影响一行时,这是一个非常干净的解决方案。
乔恩·塞格尔

我明白。但是我可以说SELECT @JNK = SomeTable从SomeTable那里SomeOtherColumn = MatchesMultipleRows ...那么为什么不在这里应用此约束呢?无论如何,谢谢,我只声明一个本地表变量并完成它。生活仍在继续。:)
AndreiRînea2012年

0
declare @status_atividade bit;

update t1 set         
    t1.idioma = t2.idioma, 
    t1.regiao = t2.regiao, 
    t1.fuso_horario = t2.fuso_horario,
    @status_atividade = t2.status_atividade

from 
    @usuario as t1  
join 
    dbo.locatario as  t2 
on 
    t1.id_locatario = t2.id_locatario

select @status_atividade
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.