怎样用 sql语句把符合日期值条件的数据选择出来?(100分)

  • 主题发起人 zhaojingang
  • 开始时间
Z

zhaojingang

Unregistered / Unconfirmed
GUEST, unregistred user!
现在需要把1978年01月01前出生的记录选择出来,用下面的语句没有作用:
ji_ben_tab :人员数据表 birth_day:出生日期
select * from ji_ben_tab where birth_day<1978-01-01
请问上述功能怎样实现? 请赐教
 
你可以用动态sql 实现,日期控件直接用datetimepicker,
query1.close;
query1.sql.clear;
query1.sql.add('select * from ji_ben_tab where birth_day <=:da');
query1.parambyname('da').asdate:=datetimepicker1.date;
query1.open;
 
什么数据库?这样试试看
select * from ji_ben_tab where birth_day<'1978-01-01'
 
select * from ji_ben_tab where to_char(birth_day,'YYYY-MM-DD')<'1978-01-01'

for Oracle
 
同意楼上的
 
如果是SQL可将日期作为字符类型进行比较
 
我的数据库是access ,没有to_char()函数
 
adoquery2.SQL.Add('select * from ji_ben_tab where ')
adoquery2.SQL.Add(' birth_day <= ''' + FormatDateTime( 'yyyy-mm-dd', datetime_end.datetime ) + '''');
datetime_end.datetime 是你要比较的日期
 
看看这个
select * from ji_ben_tab where birth_day<#1978-01-01#
 
select * from ji_ben_tab where birth_day<'1978-01-01'

者把日期转换成字符类型再过虑
 
谢谢大家,特别感谢tseug,一切ok!
 
query1.sql.add('select * from 表 where birth_day <=:b');
query1.parambyname('b').asdatetime:=datetimepicker1.datetime;
 
clientdataset1.commandtext:='select * from "表" where birth_day='+''''+edit.text+'''';
edit1中可输入日期
 
select * from ji_ben_tab where birth_day<'1978-01-01 00:00:00'
这样就可以了
 
顶部