Solved

Quick Report & Delphi Need Help!

Posted on 2002-05-13
16
181 Views
Last Modified: 2010-04-04
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!
0
Comment
Question by:accurates
  • 4
  • 4
  • 3
  • +3
16 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7007765
StrToTime is a Delphi function and might not be supported by the database driver you are using.

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
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 7007766
? hmm,

add a column (datetime or number(float)),
code a migration-tool, which converts your timestring to datetime or float into this new field

now you can easily use this new field in an order by clause

meikl ;-)
0
 

Author Comment

by:accurates
ID: 7007815
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.
0
 

Author Comment

by:accurates
ID: 7007818
Hi Kretzschmar,

That is a good idea. I'll try it and if it works you get the points.

Thank You!
0
 
LVL 1

Expert Comment

by:TAZI
ID: 7008220
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
0
 

Author Comment

by:accurates
ID: 7008896
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..)
0
 
LVL 17

Expert Comment

by:geobul
ID: 7009313
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
0
 
LVL 17

Expert Comment

by:geobul
ID: 7009493
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:ITugay
ID: 7010364
Hi accurates,
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7010414
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 ;-)
0
 
LVL 1

Expert Comment

by:TAZI
ID: 7010417
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
0
 
LVL 9

Expert Comment

by:ITugay
ID: 7010432
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.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 7010434
hmm, doesn't work.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7010442
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 ;-)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 7010458
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
0
 

Author Comment

by:accurates
ID: 7011109
Thanks Kretzschmar,

I think that this is the simplest way to achieve this.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 201
Delphi Dbf export problem to a Visual Foxpro application 6 161
Correct Component for Shopping Cart. 2 95
Making delphi communicate with a c# service 16 88
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now