这个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;
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;
试试select * from table where (年>'2000' and 年<'2003' ) or
(年='2000' and cast(月 as int)>=2) or (年<='2003' and cast(月 as int)<=9)
试试select * from table where (年>'2000' and 年<'2003' ) or
(年='2000' and cast(月 as int)>=2) or (年<='2003' and cast(月 as int)<=9)
这样的一个string 在sql里把它做为日期查询
select .. where day >=2002-02-01 and day <2003-09-01
没测试过,我这边没有Sql Server服务器select * from table where (年>'2000' and 年<'2003' ) or
(年='2000' and cast(月 as int)>=2) or (年='2003' and cast(月 as int)<=9)
left(convert(varchar,日期字,12),4)<='0002'
and
left(convert(varchar,日期字,12),4)>='0309'
SORRY
看了一下,大于小于号搞错啦,经调试完全可行select * From 表 where
left(convert(varchar,日期字,12),4)>='0002'
and
left(convert(varchar,日期字,12),4)<='0309'
你符合的记录比方是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了
或者你可以转换类型,把两个字段变成一个再比教