当前位置: 移动技术网 > IT编程>数据库>MSSQL > sqlserver 局部变量的使用

sqlserver 局部变量的使用

2017年12月12日  | 移动技术网IT编程  | 我要评论

车前子的作用与功效,外卖小哥蒙面送餐,淘优客

a. 使用 declare
下例使用名为 @find 的局部变量检索所有姓以 ring 开头的作者信息。
复制代码 代码如下:

use pubs
declare @find varchar(30)
set @find='ring%'
select au_lname,au_fname,phone
from authors
where au_lname like @find


@find就是一个局部变量。

b. 在 declare 中使用两个变量
下例从 binnet & hardley (pub_id = 0877) 的雇员中检索从 1993 年 1 月 1 日起所雇佣的雇员名称。
复制代码 代码如下:

use pubs
set nocount on
go
declare @pub_id char(4), @hire_date datetime
set @pub_id = '0877'
set @hire_date = '1/01/93'
-- here is the select statement syntax to assign values to two local
-- variables.
-- select @pub_id = '0877', @hire_date = '1/01/93'
set nocount off
select fname, lname
from employee
where pub_id = @pub_id and hire_date >= @hire_date

下面是结果集:

fname lname
-------------------- ------------------------------
anabela domingues
paul henriot

(2 row(s) affected)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网