declare @maxvalue int select @maxvalue=max(求最大值的列) from 表名
declare @int as int以下两种方法都行.select @int = max(int列) from tbset @int = (select max(int列) from tb)
create table tb(col int) insert into tb select 2 union all select 8 union all select 3 go declare @max int select top 1 @max=COL from tb order by col desc select @max /* ----------- 8(1 行受影响) */ go drop table tb
if object_id('tb') is not null drop table tb go create table tb ( id int, name varchar(10) ) go insert into tb select 1,'张三' union all select 3,'李四' union all select 2,'王五' union all select 8,'赵六' go declare @i int -- 定义变量 select @i=max(id) from tb --用max函数取最大值 select @i --显示变量值 /* ----------- 8(1 行受影响)*/
delcare @a int set @a=max(要查的列) from table(要查询的表)select @a
declare @id int set @id=select max(列) as zuida from table1
declare @maxvalue int
select @maxvalue=max(求最大值的列) from 表名
insert into tb select 2 union all select 8 union all select 3
go
declare @max int
select top 1 @max=COL from tb order by col desc
select @max
/*
-----------
8(1 行受影响)
*/
go
drop table tb
if object_id('tb') is not null
drop table tb
go
create table tb
(
id int,
name varchar(10)
)
go
insert into tb
select 1,'张三' union all
select 3,'李四' union all
select 2,'王五' union all
select 8,'赵六'
go
declare @i int -- 定义变量
select @i=max(id) from tb --用max函数取最大值
select @i --显示变量值
/*
-----------
8(1 行受影响)*/
set @a=max(要查的列) from table(要查询的表)select @a
set @id=select max(列) as zuida from table1
select @int=max(指定字段) from tb
select @max=max(col) from tbl