这个sql语句如何写???(sql server2000)table1姓名,工号,年, 月
 dd   001  2000   2
 ss   002  2001   7
 er   003  1999   12
 tr   100  2003   1如何查询出在
   >=2000年2月 <=2003年9月 的数据?????我是这样写得好象不对!dm.cds_chg_tj.close;
dm.cds_chg_tj.commandtext:='select * from table1 where  ((年>='''+c_startyear.Text+''')                            and (月>='''+c_startmonth.Text+''')) and ((年<='''+c_endyear.Text+''')                            and (月<='''+c_endmonth.Text+''')) order by 年,月 asc'; //
dm.cds_chg_tj.open;

解决方案 »

  1.   

    先把年,月字段的取出来,组成一个整型变量,然后在用SQL语句来写!
      

  2.   

    那该如何写这个sql语句???
      

  3.   

    当然不多,你的月是 char 类型的吧,
    试试select * from table where (年>'2000' and 年<'2003' ) or
    (年='2000' and cast(月 as int)>=2) or (年<='2003' and cast(月 as int)<=9)
      

  4.   

    你的年、月是 char 类型的吧,
    试试select * from table where (年>'2000' and 年<'2003' ) or
    (年='2000' and cast(月 as int)>=2) or (年<='2003' and cast(月 as int)<=9)
      

  5.   

    可不可以设计一个计算字段day=年+"-"+月+"-1"
    这样的一个string 在sql里把它做为日期查询
    select .. where day >=2002-02-01 and day <2003-09-01
      

  6.   

    不好意思,刚才那个<= 应该为 =
    没测试过,我这边没有Sql Server服务器select * from table where (年>'2000' and 年<'2003' ) or
    (年='2000' and cast(月 as int)>=2) or (年='2003' and cast(月 as int)<=9)
      

  7.   

    呵呵,使用CONVERT(VARCHAR,datetime,int)函数就可以拉select * From 表 where
     left(convert(varchar,日期字,12),4)<='0002'
    and 
     left(convert(varchar,日期字,12),4)>='0309'
      

  8.   

    呵呵
    SORRY 
    看了一下,大于小于号搞错啦,经调试完全可行select * From 表 where
     left(convert(varchar,日期字,12),4)>='0002'
    and 
     left(convert(varchar,日期字,12),4)<='0309'
      

  9.   

    我是了一下!把我的字段改为int就可以了!
      

  10.   

    注意,你不能直接用and来连接;这样的话
    你符合的记录比方是2002年12 月,小于2003,但由于大于9 而造成error
    create table test(
    name varchar2(10),
    eid  varchar2(10),
    year varchar2(4),
    month varchar2(2)
    );insert into test values('aa','001','2000','2');
    insert into test values('dd','002','2001','7');
    insert into test values('cc','003','1999','12');
    insert into test values('bb','004','2003','1');select * from test;
    select * from test where year>'2000' or year='2000' and month>='2'
    intersect
    select * from test where year<'2003' or year='2003' and month<='9';你在前台直接调用就ok了
    或者你可以转换类型,把两个字段变成一个再比教