多变量对应多字段赋值 select对多个变量赋值

如果有多条记录,则获得最后一个:
SQL code
create table tablea(id int,ip varchar(15),apps varchar(10))
insert into tablea select 23,'127.0.0.1','aaa'
insert into tablea select 23,'127.0.0.2','abb'
go
declare @Variable1 varchar(15),@Variable2 varchar(10)
select @Variable1 = ip ,@Variable2 = apps from tablea where id = 23

select @Variable1,@Variable2
/*
--------------- ----------
127.0.0.2       abb

(1 行受影响)

*/
go
drop table tablea

你可能感兴趣的:(select)