能 举个详细点的例子,如有条记录的MYdate是8:00 与当前时间怎么比较如 select * from TB where MYdate<当前时间用SQL语句怎么写?
select * from tb where convert(varchar(11),getdate(),120)+mydate+':00'<getdate() --注意mydate必须是5位的形式,比如08:00,而不能是8:00,否则要自己补0 --还有,你一定要这样的话虽然是可以的,但是是用不到索引的,因为字段上用了函数!用3楼是可以走索引的!
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 行受影响)
select * from SAQ where col>=convert(varchar(5),getdate(),108)
--大于小于根据自己需求改,如果不懂的话select convert(varchar(5),getdate(),108)看下结果
其实转时间类型也就是拼字符串,有意思么?
select convert(varchar(11),getdate(),120)+'14:00'+':00'
--这样就隐式转换为当前日期的时间类型了
select * from tb where convert(varchar(11),getdate(),120)+mydate+':00'<getdate()
--注意mydate必须是5位的形式,比如08:00,而不能是8:00,否则要自己补0
--还有,你一定要这样的话虽然是可以的,但是是用不到索引的,因为字段上用了函数!用3楼是可以走索引的!