日期:2014-05-17  浏览次数:20789 次

Access数据库 :要查找处于两个字符串之间的值,怎么写?
private void selectActivity(int index, string s1,string s2)
{

  string sql= "select * from acttable where where act_start>='" + s1 + "' and act_stop<='" + s2 + "'"; 

}
我要在数据库中查找大于s1 且小于s2之间的所有记录,但照上面sql语句执行 ,不对!求大神!!!!

------解决方案--------------------
去掉单引号。
------解决方案--------------------
是什么类型?如果日期的话试试看between
------解决方案--------------------
string sql= "select * from acttable where where act_start>='" + s1 + "' and act_stop<='" + s2 + "'";

里面多了个where

string sql= "select * from acttable where act_start>='" + s1 + "' and act_stop<='" + s2 + "'";
另外还可以试试

string sql= "select * from acttable where act_start between #" + s1 + "# and #" + s2 + "#";

------解决方案--------------------
SQL code

DECLARE @t table
(
    id int,
    cDate datetime
)

insert into @t
  select 1, GETDATE()
  union
  select 2, DATEADD("D",1,GETDATE())
  union
  select 3, DATEADD("D",2,GETDATE())
  
DECLARE @start datetime='2012-10-04'
DECLARE @end datetime='2012-10-07'
SELECT *
FROM @t
WHERE cDate between @start and @end

--测试结果
--1    2012-10-04 15:40:33.360
--2    2012-10-05 15:40:33.360
--3    2012-10-06 15:40:33.360