微软平台技术学习笔记

学习,思考,实践

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

先想想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.

posted on 2009-04-01 17:38  旴江老段  阅读(448)  评论(0编辑  收藏  举报