表SAQ里里有个nvarchar(5)类型的字段 数据如下:08:00 、14:00 、····
怎么把它转换为时间类型并且与当前时间进行对比?

解决方案 »

  1.   


    declare @time nvarchar(5)
    set @time = '12:00'select (case when @time>=substring(convert(varchar(8),getdate(),108),1,5) then 1 else 0 end) [1]
    select substring(convert(varchar(8),getdate(),108),1,5)/*******************1
    -----------
    1(1 行受影响)
    --------
    10:43(1 行受影响)
      

  2.   


    select * from SAQ where col>=convert(varchar(5),getdate(),108)
    --大于小于根据自己需求改,如果不懂的话select convert(varchar(5),getdate(),108)看下结果
      

  3.   

    饿  我要吐血了 ,我是想把nvarchar类型的值转换为时间类型,不是时间类型转换为nvahrchar类型
      

  4.   

    反正都是比较大小,结果都是一样的,为什么要选择麻烦的而放弃简单的?
    其实转时间类型也就是拼字符串,有意思么?
    select convert(varchar(11),getdate(),120)+'14:00'+':00'
    --这样就隐式转换为当前日期的时间类型了
      

  5.   

    能 举个详细点的例子,如有条记录的MYdate是8:00 与当前时间怎么比较如 select *  from TB  where MYdate<当前时间用SQL语句怎么写?
      

  6.   


    select * from tb where convert(varchar(11),getdate(),120)+mydate+':00'<getdate()
    --注意mydate必须是5位的形式,比如08:00,而不能是8:00,否则要自己补0
    --还有,你一定要这样的话虽然是可以的,但是是用不到索引的,因为字段上用了函数!用3楼是可以走索引的!