我存的时间 是varchar型,内容是“12:30”、“13:40”这类的数据,请问,要怎么比较大于12:30的时间呢?
这个是varchar型哦,要当成时间来比。
最好给出具体的代码,谢谢了!

解决方案 »

  1.   

    --前提是你的数据是能转成时间的create table #t(tt varchar(10))insert into #t
    select '01:20'
    union all
    select '10:11'
    union all
    select '10:18'
    union all
    select '12:11'
    union all
    select '11:07'
    union all
    select '23:11'select * from #t where cast(('2009-11-05 '+tt) as datetime)>=cast('2009-11-05 12:00' as datetime)
      

  2.   

    select case when 
     datediff(hh,getdate(),cast(convert(varchar(10),getdate(),120)+' '+'12:30' as datetime))<0 then '大于12:30'
    else '小于12:30' end/*----------
    大于12:30(1 行受影响)*/
      

  3.   

    select case('12:30' as datetime);
      

  4.   

    好像没明白我的意思呀!
    我是说我的数据是“12:30”,然后要查找,数据库中A列的数据在12:30之后的,但是A列是varchar型
      

  5.   

    3楼的getdate()换成A列的名字就行了
    select 
     case when 
       datediff(hh,a,cast(convert(varchar(10),getdate(),120)+' '+'12:30' as datetime))<0 then '大于12:30'
    else '小于12:30' end
      

  6.   

    查找 
    select 
      *  
    from 
      tb 
    where 
      datediff(hh,a,cast(convert(varchar(10),getdate(),120)+' '+'12:30' as datetime))<0
      

  7.   

    --用秒更加精确select 
      *  
    from 
      tb 
    where 
      datediff(ss,a,cast(convert(varchar(10),getdate(),120)+' '+'12:30' as datetime))<0
      

  8.   


    datediff里面的参数分别代表什么呢?
      

  9.   


    --写错了一点
    select 
      *  
    from 
      tb 
    where 
      datediff(ss,a,cast(convert(varchar(10),a,120)+' '+'12:30' as datetime))<0
    --ss代表秒
    --a代表你的时间列
    --后面的是a时间列那天的12:30
      

  10.   

    datetime 类型的优先级要高,两个值比较时,会先将字符串转换为datetime 类型,
      

  11.   


    WHEN CONVERT(INT,REPLACE(A,':',''))>1230
      

  12.   

    DROP TABLE A;CREATE TABLE A(ID INT IDENTITY(1,1), TIMES VARCHAR(5));
    INSERT INTO A(TIMES)
    SELECT
    '09:12' UNION ALL SELECT
    '00:01' UNION ALL SELECT
    '08:08' UNION ALL SELECT
    '12:31' UNION ALL SELECT
    '13:01';SELECT * FROM A WHERE TIMES>'12:30';SELECT * FROM A 
    WHERE CONVERT(INT,REPLACE(TIMES,':',''))>1230;--REPLACE函数是来凑热闹的!