Select * from 表 where Time between time1 and time2orSelect * from 表 where Time>=time1 and Time<=time2

解决方案 »

  1.   

    Select * from yourTable where Time between time1 and time2
      

  2.   

    select * from yourtable where [time] between @time1 and @time2
    select * from yourtable where [time]>=@time1 and [time]<=@time2
      

  3.   

    假设 time,time1,time2 均是DateTime 类型,只比较时间部分
    select * from Tab where right(convert(varchar(20),time,120),8)
    between right(convert(varchar(20),time1,120),8)
    and right(convert(varchar(20),time2,120),8)
      

  4.   

    Select * from 表 where 时间列 between @time1 and @time2
    Select * from 表 where 时间列 between '1999-1-1' and '1999-1-31'
      

  5.   

    time,time1,time2 均是DateTime 类型 ,  我要比较的是全部!
      

  6.   

    Select * from 表 where 时间列 between @time1 and @time2
    Select * from 表 where 时间列 between '1999-1-1 10:10:10' and '1999-1-31 10:10:10'
      

  7.   

    写个例子启发,这种方法在程序中使用更见优势1。创建一个自定义函数(因为经常会用到)
    CREATE FUNCTION [dbo].[UF_DatetimeToInt] (@dtDateTime datetime)  
    RETURNS int 
    AS--*****--  
    BEGIN 
      declare @iDateInt int  set  @iDateInt = year(@dtDateTime)*10000 + month(@dtDateTime)*100 + day(@dtDateTime)
      return @iDateInt
      
    END
    2。写SQL语句
     select * from tab 
      where dbo.UF_DatetimeToInt(time) > dbo.UF_DatetimeToInt(time1) 
      and dbo.UF_DatetimeToInt(time)  < dbo.UF_DatetimeToInt(time2)
      

  8.   

    Select * from 表 where Time between time1 and time2