select * from tableGet order by time得到数据如图所示
select * from tableGet where time>='2013年10月28日' and  '2013年10月29日'<time
我想查询10月28号到10月29号之间的数据这么些对吗??

解决方案 »

  1.   


    改为这样,把后面的< 改为> :
    select * from tableGet where time>='2013-10-28' and  '2013-10-29'>time
      

  2.   

     time between '2013-10-28' and '2013-10-29'
      

  3.   

    对了上面的语句只能查询28号一天的数据,你想查询28、29号的:
    select * from tableGet where time>='2013-10-28' and  '2013-10-29'>=time还是只有28号的:
    select * from tableGet where time>='2013-10-28' and  '2013-10-29'>time
      

  4.   


    select * from tableGet 
    where time between '2013-10-28' and '2013-10-29'
    order by time
      

  5.   

    之间的数据,那么也就是28的数据
    那么这么写select * from tableGet 
    where convert(char(10),time,120)='2013-10-28'
    order by time也就是年月日是2013-10-28,不管时分秒
      

  6.   


    要仔细后面的应该是小于号哈,改写一下就是:select * from tableGet where time>='2013-10-28' and  time > '2013-10-29'
      

  7.   

    --一般要用convert()函数格式化日期select * 
    from tableGet 
    where convert(char(10),[time],120) between '2013-10-28' and '2013-10-29'
      

  8.   


    要仔细后面的应该是小于号哈,改写一下就是:select * from tableGet where time>='2013-10-28' and  time > '2013-10-29'你还是改错了
      

  9.   


    再改一下:
    select * from tableGet where time>='2013-10-28' and  time <'2013-10-29'
      

  10.   


    要仔细后面的应该是小于号哈,改写一下就是:select * from tableGet where time>='2013-10-28' and  time > '2013-10-29'你还是改错了
    呵呵,还真是改错了:
    select * from tableGet where time>='2013-10-28' and  time <= '2013-10-29'
      

  11.   

    select * from tableGet where time>='2013年10月27日' and  '2013年10月30日'>time改成这样还是查不错。
      

  12.   


    这样呢?:
    select * from tableGet where time>='2013年10月27日' and  '2013年10月30日'<time
      

  13.   

    用了dateTimePicker2控件出来的是2013年10月28日select * from tableGet where time>='2013年10月28日' and  '2013年10月29日'<time
      

  14.   

    应该是格式问题,日期中不能包含“年”“月”“日”,只能这样:
    select * from tableGet where time>='2013-10-27' and  time<'2013-10-30'
      

  15.   

    这样吧:
    select * from tableGet 
    where time>=replace(replace(replace('2013年10月27日','年','-'),'月','-'),'日','-') 
    and  time<replace(replace(replace('2013年10月30日','年','-'),'月','-'),'日','-')
      

  16.   


    select * from tableGet 
    where time>=replace(replace(replace('2013年10月27日','年','-'),'月','-'),'日','-') 
    and  time<replace(replace(replace('2013年10月30日','年','-'),'月','-'),'日','-')
      

  17.   

    我上面把年、月、日,给替换成“-”了,这样应该可以了select * from tableGet 
    where time>=replace(replace(replace('2013年10月27日','年','-'),'月','-'),'日','-') 
    and  time<=replace(replace(replace('2013年10月30日','年','-'),'月','-'),'日','-')
      

  18.   

    string getString = "select * from tableGet where convert(char(10),[time],120)>='" + dateTimePicker1.Value.Date.ToShortDateString() + "' and  '" + dateTimePicker2.Value.Date.ToShortDateString() + "'>time;";
    最终结果写成这样是可以的不过想问一下,加红色标注的这个是什么意思?转义时间类专成字符串类,为什么还要写成【time】,120呢??
      

  19.   

    因为以前使用money的话只要(char(10),money)就好了,所以这个转义日期中的120是什么意思啊?
      

  20.   


    哦 这个convert是个转化函数,把[time]转出了一个字符串,类似于'2013-10-28'这样,因为你后面的控件,返回的也是字符串,两个字符串进行比较
      

  21.   

    因为以前使用money的话只要(char(10),money)就好了,所以这个转义日期中的120是什么意思啊?
      

  22.   


    哦,120是一个styleID,表示了转化成哪一种日期格式:就是转化为: yyyy-mm-dd hh:mi:ss(24h)  这种格式
      

  23.   

    http://www.w3school.com.cn/sql/func_convert.asp
      

  24.   

    你看看这个就明白了哈,其实我也记不住那么多的ID,用到了查一下就行:http://www.w3school.com.cn/sql/func_convert.asp
      

  25.   

    CAST 和 CONVERT (Transact-SQL)http://msdn.microsoft.com/zh-cn/library/ms187928.aspx