select max([101(c)]  from 表
union all
select max([102(c)]  from 表
union all
select max([103(c)]  from 表
...

解决方案 »

  1.   

    --------如果隻要三列select [101(c)]=max([101(c)])   from 表  union all
    select [102(c)]=max([102(c)])   from 表  union all
    select [103(c)]=max([103(c)])   from 表
      

  2.   

    declare @sql varchar(8000)
    set @sql = 'select '''', 0'
    select @sql = @sql + ' union all select ''' + name + ''', max(' + name + ') from yourtable' from syscolumns where id = object_id('yourtable')
    exec( @sql )
      

  3.   

    select max(101(c)) as 101(c) from a
    union max(102(c)) as 102(c) from a
    union max(103(c)) as 103(c) from a
      

  4.   

    这个查询难就难在,我不能预先知道字段的名字,也不知道字段的个数。
    可能是101(C),也可能是102(BB)...
      

  5.   

    declare @str varchar(1000)
    set @str=''
    select @str=@str+' select '''+name+''', max('+name+') from test1  union all' from syscolumns where id=object_id('test1')
    set @str=left(@str,len(@str)-9)
    print @str
    exec( @str)
      

  6.   

    我的数据是从其它软件生成并通过Excel导入的,所以无法知道字段的信息
      

  7.   

    rfq(任凤泉) 的方法可行
    不过由于列太多了,超过了varchar最大8000字符的限制,text也无法用于局部变量