if exists(select name from sysobjects where name='tblA' and xtype='U')
   drop table tblA
if exists(select name from sysobjects where name='tmp' and xtype='U')
   drop table tmpcreate table tblA(
  BH int not null,
  GZLB int not null,
  JE int not null
)
goinsert tblA values(1,      1,       100)
insert tblA values(2,      1,       150)
insert tblA values(3,      1,       110)
insert tblA values(4,      1,       99)
insert tblA values(5,      1,       180)
insert tblA values(6,      1,       150)
insert tblA values(7,      1,       160)
insert tblA values(8,      1,       170)
insert tblA values(9,      1,       130)  declare @sql varchar(600)
  set @sql = 'select'
  
  select a.[name] as 'name' into tmp from syscolumns a inner join
      sysobjects b ON a.id = b.id
      where (b.name = 'tblA')
  
  select @sql = @sql +' sum('+ name +') as ''all '+ name +''',' from tmp
  set @sql = substring(@sql, 1, len(@sql)-1) +' from tblA group by BH'
  exec(@sql)