accurates
asked on
Quick Report & Delphi Need Help!
I have a database app that I am modifying.
There are times involved and they are stored in the database as strings (10:00pm, 05:00am etc..).
I need to be able to print some reports in time order (not string order) and have tried an SQL Query:
Select * From ResMas.dbf
Order By strtotime(DELSTIME)
This throws back an error saying "Invalid Keyword" anybody got any ideas on how to do this?
500 points available!
There are times involved and they are stored in the database as strings (10:00pm, 05:00am etc..).
I need to be able to print some reports in time order (not string order) and have tried an SQL Query:
Select * From ResMas.dbf
Order By strtotime(DELSTIME)
This throws back an error saying "Invalid Keyword" anybody got any ideas on how to do this?
500 points available!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Dragonslayer,
The tables are DBASEV tables.
(SQL works with or without the ".dbf". It was just for informational purposes}
The statment will not work because string order sees
12:00am as greater than 05:00am.
The tables are DBASEV tables.
(SQL works with or without the ".dbf". It was just for informational purposes}
The statment will not work because string order sees
12:00am as greater than 05:00am.
ASKER
Hi Kretzschmar,
That is a good idea. I'll try it and if it works you get the points.
Thank You!
That is a good idea. I'll try it and if it works you get the points.
Thank You!
Hi ..
I tried the following.
I created a temporary table with the following data:
szTime
-------
12:00am
15:00pm
17:00pm
10:00am
05:00am
I select using this code:
Select * from #Temp
order by convert(datetime,szTime)
szTime
-------
12:00am
05:00am
10:00am
15:00pm
17:00pm
what time would you like to be first ??
Regards
I tried the following.
I created a temporary table with the following data:
szTime
-------
12:00am
15:00pm
17:00pm
10:00am
05:00am
I select using this code:
Select * from #Temp
order by convert(datetime,szTime)
szTime
-------
12:00am
05:00am
10:00am
15:00pm
17:00pm
what time would you like to be first ??
Regards
ASKER
Hi Tazi,
I tried this but I get the error "Invalid Use Of Keyword".
My times are not in as military (17:00pm etc..) they are stored as (05:00pm, 02:00pm etc..)
I tried this but I get the error "Invalid Use Of Keyword".
My times are not in as military (17:00pm etc..) they are stored as (05:00pm, 02:00pm etc..)
Hi,
SELECT aaa, bbb, DelsTime,
SUBSTRING(DelsTime FROM 1 FOR 5) AS TheTime,
SUBSTRING(DelsTime FROM 6 FOR 2) AS TheExt
FROM ResMas.dbf ORDER BY TheExt,TheTime
Regards, Geo
SELECT aaa, bbb, DelsTime,
SUBSTRING(DelsTime FROM 1 FOR 5) AS TheTime,
SUBSTRING(DelsTime FROM 6 FOR 2) AS TheExt
FROM ResMas.dbf ORDER BY TheExt,TheTime
Regards, Geo
Forgot to say:
1. You have to encounter all fields to be selected;
2. When printing, skip the last two fields as they are being used for ordering purpose only.
Regards, Geo
1. You have to encounter all fields to be selected;
2. When printing, skip the last two fields as they are being used for ordering purpose only.
Regards, Geo
Hi accurates,
hi igor,
do i miss something in your comment above?
about geo's soltuion,
should work, but depending on the amount of data,
very slow
meikl ;-)
do i miss something in your comment above?
about geo's soltuion,
should work, but depending on the amount of data,
very slow
meikl ;-)
Hi accurates
What database are you using ?? The following code
Select * from #Temp
order by convert(datetime,szTime)
is used in SQL Server 7.0.
Data in Table:
szTime
-------
03:00pm
05:00pm
05:00am
10:00am
03:00am
12:00am
If I select ... using
Select * from #Temp
order by convert(datetime,szTime)
szTime
-------
12:00am
03:00am
05:00am
10:00am
03:00pm
05:00pm
Regards
What database are you using ?? The following code
Select * from #Temp
order by convert(datetime,szTime)
is used in SQL Server 7.0.
Data in Table:
szTime
-------
03:00pm
05:00pm
05:00am
10:00am
03:00am
12:00am
If I select ... using
Select * from #Temp
order by convert(datetime,szTime)
szTime
-------
12:00am
03:00am
05:00am
10:00am
03:00pm
05:00pm
Regards
hi meikl,
yes, something wrong, I typed some text there. Ok, here is it.
I think that it possible to join two queries from the same table. First which has only 'pm' data and second with only 'am' data. Both of them simply sorted by DelsTime.
May be I'm wrong. Not tested yet.
---------
Igor.
yes, something wrong, I typed some text there. Ok, here is it.
I think that it possible to join two queries from the same table. First which has only 'pm' data and second with only 'am' data. Both of them simply sorted by DelsTime.
May be I'm wrong. Not tested yet.
---------
Igor.
hmm, doesn't work.
igor,
something like
select
whateverfields,
timefield
from atable
where timefield like '%am'
order by timefield
union all
select
whateverfields,
timefield
from atable
where timefield like '%pm'
order by timefield
(not tested)
meikl ;-)
something like
select
whateverfields,
timefield
from atable
where timefield like '%am'
order by timefield
union all
select
whateverfields,
timefield
from atable
where timefield like '%pm'
order by timefield
(not tested)
meikl ;-)
seems the problem is in 12:00am
....
where timefield like '12:00am'
...
union
where timefield not like '12:00am'
order by timefield
I think that it is easy and fast way
....
where timefield like '12:00am'
...
union
where timefield not like '12:00am'
order by timefield
I think that it is easy and fast way
ASKER
Thanks Kretzschmar,
I think that this is the simplest way to achieve this.
I think that this is the simplest way to achieve this.
Anyway, if the data stored as "05:00am", "10:00pm", etc. then I believe string comparison will do okay
just do a
SELECT * FROM ResMas ORDER BY DelsTime
(BTW, what's the .dbf for? Hmm...)
HTH
DragonSlayer