如有一个datatable,其中有一名为date的列, 
        date 
      200801 
      200802 
      200802 
      200803 
      200804 
      200805 
如果不用对表进行for循环操作,如果相同的记录,只取其一条。我想查询的结果为 200801 200802 200803 200804 200805 
请赐教! 

解决方案 »

  1.   

    为什么不把数据过滤好了再放到DataTable中呢
      

  2.   

    SQL处理得么??
    单列?select distinct [date] from tablename
    多列?
    declare @t table([id] int identity(1,1),[date] varchar(6))
    insert @t select '200801'
    union all select '200802' 
    union all select '200802' 
    union all select '200803'
    union all select '200804'
    union all select '200805'
    select *
    from @t t
    where not exists(select 1 from @t where t.[date]=[date] and t.[id]>[id]) 
    /*(所影响的行数为 6 行)id          date   
    ----------- ------ 
    1           200801
    2           200802
    4           200803
    5           200804
    6           200805(所影响的行数为 5 行)
    */
      

  3.   

    回答2楼的朋友,我所列出来的列只是datatable中的其中一列,肯定有可能会有重复的。
    回答3楼的朋友,不是对数据库进行操作,是对datatable进行操作。
      

  4.   

    select distinct date from datatable