declare @ghy_table table(maxvalue int)
insert @ghy_table
select maxvalue=(case when ghy1>ghy4 then a end) from a as mostselect * from @ghy_table
where @ghy_table.maxvalue is not null 

解决方案 »

  1.   

    declare @ghy_table table(maxvalue int)
    insert @ghy_table
    select maxvalue=(case when ghy1>ghy4 then a end) from a as mostselect * from @ghy_table A
    where A.maxvalue is not null
      

  2.   

    declare @ghy_table varchar(1000)
    declare @sql varchar(1000)
    set @ghy_table='(select maxvalue=(case when ghy1>ghy4 then a end) from a ) AA'
    set @sql='select * from '+ @ghy_table+' where AA.maxvalue is not null'exec (@sql)
      

  3.   

    服务器: 消息 137,级别 15,状态 2,行 6
    必须声明变量 '@ghy_table'。
    出错啊,,where A.maxvalue is not null在最后一条中出错的,怎么办啊??
      

  4.   

    declare @ghy_table table(maxvalue int)
    insert @ghy_table
    select maxvalue=(case when ghy1>ghy4 then a end) from a as mostselect * from @ghy_table
    where @ghy_table.maxvalue is not null 
    是这条语句出错的,怎么办,
      

  5.   

    已经解决
    --------------------------------------------------------------------
    declare @ghy_table table(maxvalue int)
    insert @ghy_table
    select maxvalue=(case when ghy1>ghy4 then a end) from a as mostselect * from @ghy_table
    where @ghy_table.maxvalue is not null 
    -----------------------------------------------------------------改成:
    select maxvalue=(case when ghy1>ghy4 then ghy1 end) from a as mostOK..