1,select * from table where Convert(varChar(10),rq,20)=Convert(varChar(10),GetDate(),20)2,select * from table where Convert(varChar(10),rq,20)=Convert(varChar(10),DateAdd(d,-1,GetDate()),20)3,select * from table where Convert(varChar(10),rq,20)<=Convert(varChar(10),GetDate(),20) and Convert(varChar(10),rq,20)>=Convert(varChar(10),DateAdd(d,-15,GetDate()),20)

解决方案 »

  1.   

    select * from table where datediff(day,rq,getdate())<15
      

  2.   

    select * from table where datediff(day,rq,getdate())<15 order by rq
      

  3.   

    select * from where date between getdate()-15 and getdate()
      

  4.   

    select * from table where datediff(day,rq,getdate())<15 可以,但这条语句的效率会很低,因为在 where 表达式的左边使用函数会显著降低效率。最好是select * from table where rq>=DateAdd(day,-15,GetDate()) and rq<=GetDate()
      

  5.   

    SELECT * FROM TABLE WHERE DATEDIFF(DAY,rq,GETDATE())=0
    SELECT * FROM TABLE WHERE DATEDIFF(DAY,rq,GETDATE())=1
    SELECT * FROM TABLE WHERE DATEDIFF(DAY,rq,GETDATE())<=15
      

  6.   

    select * from table where datediff(day,rq,getdate())=0
    select * from table where datediff(day,rq,getdate())=1
    select * from table where datediff(day,rq,getdate())=15
    select * from table where rq= getdate()   --取当天数据
    select * from table where rq=getdate() -1 --取昨天天数据
    select * from table where rq=dateadd(day,-15,getdate()) --取昨天天数据

    select * from table where rq= dateadd(day,-15,getdate())  --取天15天的数据以下为格式转换:select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
    select convert(char(8),getdate(),112) ----20020101
    select convert(char(8),getdate(),108)  ---06:05:05 101 美国 mm/dd/yyyy 
    2 102 ANSI yy.mm.dd 
    3 103 英国/法国 dd/mm/yy 
    4 104 德国 dd.mm.yy 
    5 105 意大利 dd-mm-yy 
    6 106 - dd mon yy 
    7 107 - mon dd, yy 
    8 108 - hh:mm:ss 
    - 9 或 109 (*)  默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM) 
    10 110 美国 mm-dd-yy 
    11 111 日本 yy/mm/dd 
    12 112 ISO yymmdd 
    - 13 或 113 (*)  欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h) 
    14 114 - hh:mi:ss:mmm(24h) 
    - 20 或 120 (*)  ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff] 
    - 21 或 121 (*)  ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff] 
    - 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格) 
    - 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM 
    - 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM