SQL2000 数据库存在下列数据
1998-7-3
1988-5-17
1996-10-8
1989-7-31
1966
1989
1996-11-24
查询条件是输入数据段如:5-1号到8-15号
需要显示的是:
1998-7-3
1988-5-17
1989-7-31
用自带的时间函数计算差值 好像不行 因为没有时间 
请高手指点

解决方案 »

  1.   

    select * 
    from tb
    where right(convert(varchar(10),col,120),5)
    between '05-01' and '08-15'
      

  2.   

    select * from tb where isdate(col) = 1 and col ...
      

  3.   

    if not object_id('tb') is null
    drop table tb
    Go
    Create table tb([col] Datetime)
    Insert tb
    select '1998-7-3' union all
    select '1988-5-17' union all
    select '1996-10-8' union all
    select '1989-7-31' union all
    select '1966' union all
    select '1989' union all
    select '1996-11-24'
    Go
    select * 
    from tb
    where right(convert(varchar(10),col,120),5)
    between '05-01' and '08-15'
    /*
    col
    -----------------------
    1998-07-03 00:00:00.000
    1988-05-17 00:00:00.000
    1989-07-31 00:00:00.000(3 個資料列受到影響)
    */
      

  4.   

    select
     * 
    from
     tb
    where
     right(convert(varchar(10),col,120),5) between '05-01' and '08-15'
    and
     isdate(col)=1
      

  5.   

    between'05-01'and'08-15'
    这样才可以 between'5-1'and'8-15'
    如何才能更好的匹配
      

  6.   

    SELECT 
    *
    FROM
    TA
    where right(convert(char(10),cast(col as datetime) ,120),5) between'05-01' and '08-01'
      

  7.   

    如果字段是字符型
    就要先cast成日期,然後在convert 
    如果是日期型
    isdate便多余
    select
     * 
    from
     tb
    where
     right(convert(varchar(10),cast(col as datetime),120),5) between '05-01' and '08-15'
    and
     isdate(col)=1