数据库中表A:
 ID    DATE     COUNT
  1     1月      100
  1     2月      200
  1     3月      300
……………………
要求在Grid中显示如下:
      
ID            1月    2月   3 月  …………
1    COUNT    100    200    300我用的是SQL2000,应该怎么做?如果用第三方控件应该用什么控件?请指点
   

解决方案 »

  1.   

    Create table test (id int,date char(10),count int)
    go
    insert test values(1,'1月',100)
    insert test values(1,'2月',200)
    insert test values(1,'3月',300)declare @sql varchar(8000)
    set @sql = 'select id'
    select @sql = @sql + ',sum(case date when '''+date+''' then count end) ['+date+']'
     from (select distinct date from test) as a
    select @sql = @sql+' from test group by id'
    exec(@sql)--drop table test
    id          1月          2月          3月          
    ----------- ----------- ----------- ----------- 
    1           100         200         300