select * from table
  where convert(char(8), o_xssj,112) >= '20011112' and
        convert(char(8), o_xssj,112) <= '20021211' and
        substring(convert(char(8), o_xssj, 114), 1, 2) + substring(convert(char(8), o_xssj, 114), 4, 2) + substring(convert(char(8), o_xssj, 114), 7, 2) >= 091215 and
        substring(convert(char(8), o_xssj, 114), 1, 2) + substring(convert(char(8), o_xssj, 114), 4, 2) + substring(convert(char(8), o_xssj, 114), 7, 2) <= 161918这只是个笨办法。

解决方案 »

  1.   

    上述where条件中时间忘加引号了。
      

  2.   

    select * from tablename 
    where (o_xssj>'2001-11-12' and o_xssj<'2002-12-11') 
    and 
    (
    ((datename(hour,o_xssj)+datename(minute,o_xssj)+datename(second,o_xssj))>'091215')
    and 
    ((datename(hour,o_xssj)+datename(minute,o_xssj)+datename(second,o_xssj))<'161918')
    )
      

  3.   

    SELECT *
    FROM t_time
    WHERE SUBSTRING(CONVERT(nchar(10), time, 20), 1, 10) <= '2002-01-11' AND 
          CONVERT(nchar(8), time, 108) <= '16:19:18'