select * from syscloumns where id=object_id('tablename')
可以读出表中的所以列名

解决方案 »

  1.   

    select name from syscloumns where id=object_id('tablename')
      

  2.   

    我找你的意思写了一段东西,给你参考,因为不了解你的数据库中数据的具体意思,所以下面的写的肯定有问题!
    create proc f_GetNum
    @strWhere varchar(32)    --用来确定是那一行
    as
    declare @num int 
    declare @Anum int
    declare @Bnum int
    declare @tmpTbl table (anum int,bnum int)
    declare @m floatdeclare c1 cursor for 
    select * from 表 where ...= @strWhere         --选一行数据
    open c1
    fetch next c1 into @mbegin
        if(@m='A')
    begin
    @Anum=@num            -- 纪录 A 的数据
    @num=0
    end
        if(@m='B')
    begin
    @Bnum=@num            -- 纪录 B 的数据
    @num=0
    end
        else
             begin
             if(@m<60)  
        @num=@num+1        --分数小于60,就加1
             end
        fetch next c1 into @m
    end
    close c1
    deallocate c1
    insert into @tmpTbl values(@Anum,@Bnum)
    select * from @tmpTbl
    go
      

  3.   

    declare @a int,@b int
    select @a=0,@b=0select 
    @a=case col1 
      when '合格' then @a+1 else @a end,
    @a=case col2 
      when '合格' then @a+1 else @a end,
    @a=case col3 
      when '合格' then @a+1 else @a end,
    @a=case col4 
      when '合格' then @a+1 else @a end,
    ---
    from yourtableselect @a 合格数