我建立了一个数据库,在数据库表中我的时间是用三列表示的,当我在asp.net中想查询两个时间(2011-7-1,2011-9-10)之间日期的数据时,我应该怎么写sql语句

解决方案 »

  1.   

    這樣?
    select * from table1 where col1 between '2011-7-1' and '2011-9-10'
    and  col2 between '2011-7-1' and '2011-9-10'
    and  col3 between '2011-7-1' and '2011-9-10'
      

  2.   

    能不能写成select * from table where年+月+日 between 2011-7-1 and 2011-9-1的类似形式
      

  3.   

    select * from table1 where col1 between '2011-7-1' and '2011-9-10'
    or col2 between '2011-7-1' and '2011-9-10'
    or col3 between '2011-7-1' and '2011-9-10其中一列滿足都顯示用 or
      

  4.   


    select * from table where CAST(RTRIM(年)+right(100+月,2)+right(100+日,2) AS DATETIME) between '2011-7-1' and '2011-9-1'
      

  5.   

     string sql_str = "select * from TestData " +" where CAST(RTRIM(Year)+right(100+Month,2)+right(100+Date,2) AS DATETIME) between '" + Session["date1"].ToString() + "' and '" + Session["date2"].ToString() + "'"
    还是不对啊
      

  6.   


    select * from Table where 时间 between 开始时间 and 结束时间 
      

  7.   

    Session["date1"].ToString() 是开始时间,Session["date2"].ToString() 是结束时间
      

  8.   

        string sql_str = "select * from TestData  where  CAST(RTRIM(Year)+right(100+Month,2)+right(100+Date,2) AS DATETIME) between '" + Session["date1"].ToString() + "' and '" + Session["date2"].ToString() + "'"
      

  9.   


    select * from tb where dt between '2011-7-1' and '2011-9-10'
      

  10.   

    Session["date1"].ToString表示:我把起始时间放在了一个TextBox控件里面,Year。Month,Date,在数据库表中分别表示年月日。
    我的目的是取出数据库中Session["date1"].ToString和Session["date2"].ToString这两个日期之间的数据。