求一SQL语句(10分)

  • 主题发起人 主题发起人 南宫吹云
  • 开始时间 开始时间

南宫吹云

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个paradox表,有一个日期型字段和一个时间型字段。现在用一SQL语句将
2002-02-01日14:00以后,2002-05-01日14:00以前的所有数据检索出来。
日期型字段为sdate,时间型字段为stime。此SQL语句该如何写(最简单的)?
 
select * from t where (to_char(sdate) between and )
and (to_char(stime) between and )
 
select*from 表 where (转化为字符串(数据字段) between 2002-02-01 14:00 and 2002-05-01 14:00
 
你先在SQL中定义变量:
Select * from table
where Date>=:date1 and Date<=:date2
union
select * from table
where date=:date3 and time>=:time1
union
select * from table
where date=:date4 and time>=:time1
date1赋值为2002-02-02
date2赋值为2002-05-01
date3赋值为2002-02-01
date4赋值为2002-05-01
time1赋值为14:00
或者:
select * from
(select * from table
where Date>=:date1 and Date<=:date2)
where (not (Date=:date1 and time<=:time1)
and (not (Date=:date2 and time>=:time1)
date1赋值为2002-02-01
date2赋值为2002-05-01
time1赋值为14:00



 
关键是转化为字符串的函数是哪个?我用str(sdate),出错:
Capability not supported.
 
To: delphi_zm:
  我的可是paradox库啊,执行你以上的语句有错:token:select
 
转化为字符串麻烦一点可以用:datename(datepart,date)
 
我在SQL explorer 中是这样写的:
select * from
(select * from test
where sDate>='2002-01-01' and sDate<='2002-06-01')
where not (sDate='2002-01-01' and stime<='14:00:00')
and not (sDate='2002-06-01' and stime>='14:00:00')
应该也对吧?
我用的delphi5.0
 
to:bjf2001
在SQL explorer中执行不成功:
Capability not supported.
 
基本同意delphi_zm的说法,给date1,date2等负值时,应该用
Query1.parambyname('date1').asdate := '02-01-11';
....
 
为什么SQL语句,有的我在SQL SERVER中执行成功,而在DELPHI5.0自带的sql explorer中
执行不成功呢?
比如:datepart函数它就认不出来,报错。
BDE中的SQL命令只是SQL SERVER中的一个子集吗?
 
大家想想办法,bde+paradox表如何解决上面的问题?
如果用ADO连接会不会出现这样的问题?
 
这与怎么连接,没有什么大的联系。主要是你的表结构
 
最好用参数,在Query1中定义,负值:
Query1.parambyname('date1').value :=strtodate('2002-02-01')
必须这样,如果用SQL explorer没有办法,因为它将'2002-02-01'认为是个字符串,
会出现不匹配的问题。
 
date1:=strtodate('2002-02-01')
date2:=strtodate(2002-05-01'')
time:=strtotime(14:00)
select * from 表 where sdate>=:date1 and sdate<=:datae2 and stime=:time
query1.parambyname('sdata'):=date1
query1.parambyname('sdata'):=date2
query1.parambyname('stime'):=time
query1.open
date1,dat2,time 分别为上的日期和时间
 
在sql explorer,日期要写成"月/日/年"的形式,不能写"年-月-日",上面的问题可以试试:
select * from test
where sDate>='01/01/2002' and sDate<='06/01/2002' and stime>='14:00:00'
 
rifleli,按照您的说法,我将SQL语句改成这样:
select * from
(select * from test
where sDate>='01/01/2002' and sDate<='06/01/2002')
where not (sDate='01/01/2002' and stime<='14:00:00')
and not (sDate='06/01/2002' and stime>='14:00:00')
却还是出错,难道SQL EXPLORER不支持嵌套语句?
 
date1:=strtodate('2002-02-01')
date2:=strtodate(2002-05-01'')
time:=strtotime(14:00)
select * from 表 where sdate>=:date1 and sdate<=:datae2 and stime=:time
query1.params[0].asdatetime:=date1
query1.params[1].asdatetime:=date2
query1.params[2].astime:=time
query1.open
date1,dat2,time 分别为上的日期和时间
 
to :chenzheng770101,
你这样查询出来的只是2002-02-01到2002-05-01之间所有14:00的记录
看清问题再答好吗?
 
我想可能是SQL EXPLORER的SQL语句功能不全,有时在SQL SERVER中能执行的语句,在SQL 
EXPLORER中就是执行不成功。
 
后退
顶部