






















先想想select @a 都会返回什么值。
use AdventureWorks
go
declare @a varchar
select @a
select @a = 'a' from Production.Culture where 1 = 2
select @a
select @a = 'b'
select @a
select @a = 'a' from Production.Culture where 1 = 2
select @a
在看看MSDN的解释
Remarks
SELECT @local_variable is typically used to return a single value into the variable. However, when expression is the name of a column, it can return multiple values. If the SELECT statement returns more than one value, the variable is assigned the last value that is returned.
If the SELECT statement returns no rows, the variable retains its present value. If expression is a scalar subquery that returns no value, the variable is set to NULL.
One SELECT statement can initialize multiple local variables.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。