求INT列的最大值,并赋给变量,要怎么做呢

解决方案 »

  1.   


    declare @maxvalue int
    select @maxvalue=max(求最大值的列) from 表名
      

  2.   

    declare @int as int以下两种方法都行.select @int = max(int列) from tbset @int = (select max(int列) from tb)
      

  3.   

    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
      

  4.   


    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 行受影响)*/
      

  5.   

    delcare @a int
    set @a=max(要查的列) from table(要查询的表)select @a
      

  6.   

    declare @id int
    set @id=select max(列) as zuida from table1
      

  7.   

    declare @int int
    select @int=max(指定字段) from tb
      

  8.   

    declare @max int
    select @max=max(col) from tbl