表裡有這樣一些記錄:
10點  10:50的火車 
11點  null   
12點  null     
13點  null     
14點  null     
15點  null     
16點  記得打電話提醒下火車 
16點  test 
16點  tt 
16點  笑話 
17點  sdfdsf 請部怎樣顯示成:
10點  10:50的火車 
11點  null   
12點  null     
13點  null     
14點  null     
15點  null     
16點  1,記得打電話提醒下火車;2,test;3,tt;4,笑話; 
17點  sdfdsf 請指教
謝謝!

解决方案 »

  1.   

    如果我是你,我会读到datatable里面再做处理。
    不知道有没有sql高手直接读成这个样子?
      

  2.   

    看这么简单的界面设计,估计是数据库查询吧。如果是SQL Server数据库查询,你大致可以写:  declare @t(field1 nvarchar(30) primary key,field2 nvarchar(3000))
      insert @t(field1) select distinct field1 from [数据表]
      update t set 
        field2=case t.field2 when null then s.field2 else t.field2+','+s.field2
        from @t as t
        inner join [数据表] as s on t.field1=s.field1
        where s.field2 is not null
      select * from @t
    如果是复杂的ui,那么应该使用正规的ui组件开发方法。例如对于asp.net来说,首先开发一个ascx,给它参数field1,它就能产生这个field1对应的所有field2组合起来的界面(也许只显示一行简单的文字,也许很复杂的一个小程序),然后使用SQL语句“select distinct field1 from [数据表]”查询数据产生数据源绑定到DataList,并把这个ascx组件放入模板中,接受field1数据进行展示。
      

  3.   

    写在查询批处理命令中就行了,例如:SqlCommand cmd=new SqlCommand(
      @"declare @t(field1 nvarchar(30) primary key,field2 nvarchar(3000))
      insert @t(field1) select distinct field1 from [数据表]
      update t set 
        field2=case t.field2 when null then s.field2 else t.field2+','+s.field2
        from @t as t
        inner join [数据表] as s on t.field1=s.field1
        where s.field2 is not null
      select * from @t", connect);
      

  4.   

    to all:因為gahade(与君共勉)在另一帖裡(http://community.csdn.net/Expert/topic/5537/5537598.xml?temp=.2874109),回答了此問題,方法不錯,及sp1234(我喜欢不下雨的阴天)的積極響應,分就給這兩位高手.