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

解决方案 »

  1.   

    select distinct date from table
      

  2.   

    datatable也可以distinct 吗?
      

  3.   

    --> 测试数据: #T
    if object_id('tempdb.dbo.#T') is not null drop table #T
    create table #T (date varchar(6))
    insert into #T
    select '200801' union all
    select '200802' union all
    select '200802' union all
    select '200803' union all
    select '200804' union all
    select '200805'select distinct date from #T
    /*
    200801
    200802
    200803
    200804
    200805
    */declare @s varchar(8000)
    set @s=''
    select  @s=@s+date+' ' from (select distinct date from #t)as a
    select @s
    /*
    200801 200802 200803 200804 200805 
    */
      

  4.   


    你如果是.net里的datatable,怎么发到sql server来了...如果是datatable,应该只能用for循环吧
      

  5.   

    加个DISTINCT 对DATE字段去重复就可以了SELECT DISTINCT DATE FROM TABLE
      

  6.   


    select distinct date from table from 表 order by date