http://topic.csdn.net/u/20101126/17/62b9eef5-e8ba-4ac4-872a-78cd4caba2d6.html?15331
帖子地址在此,已经结贴了。
本来我以为没问题了,不过发现我不知道怎么把年份也一起查出来,给我回帖的那位朋友我发消息问他了,可是他好像不在线。
不好意思本人只有20分了

解决方案 »

  1.   

    create table [TB]([ime] datetime)
    insert [TB]
    select '2009-08-03 16:00:00' union all
    select '2009-09-01 17:00:00' union all
    select '2009-09-30 18:00:00'
    GO--> 查询结果
    SELECT * 
    FROM [TB] where convert(varchar(7),ime,120)= (select max(convert(varchar(7),ime,120)) from TB)--> 删除表格
    DROP TABLE [TB]/*ime                                                    
    ------------------------------------------------------ 
    2009-09-01 17:00:00.000
    2009-09-30 18:00:00.000(所影响的行数为 2 行)*/
      

  2.   

    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]') 
    AND type in (N'U')) 
    DROP TABLE [TB]
    GO---->建表
    create table [TB]([ime] datetime)
    insert [TB]
    select '2009-08-03 16:00:00' union all
    select '2009-09-01 17:00:00' union all
    select '2009-09-30 18:00:00'
    GO--> 查询结果
    select * from [TB] t1 
    where not exists(select 1 from [TB] t2 where CONVERT(char(6),t1.ime,112)< CONVERT(char(6),t2.ime,112))
    -----------
    ime
    2009-09-01 17:00:00.000
    2009-09-30 18:00:00.000
      

  3.   

    create table [TB]([ime] datetime)
    insert [TB]
    select '2009-08-03 16:00:00' union all
    select '2009-09-01 17:00:00' union all
    select '2009-09-30 18:00:00'
    GOselect * from tb where datediff(mm,ime,getdate())=(select max(datediff(mm,ime,getdate())) from tb)
    --取从现在起,最近月份的数据!
    ---------------
     ime
    2009-09-01 17:00:00.000
    2009-09-30 18:00:00.000