If you do an alphameric comparison, you need the date on the left.

with tbl as (select emp,
char(dte)|| ' ' || char(tim) as clocktime,punch from timecard A) , ins as (select * from tbl where punch='IN') , outs as (select * from tbl where punch='OUT') select outs.emp, (select min(ins.clocktime) from ins where ins.emp = outs.emp and ins.clocktime > outs.clocktime) as intime, outs.clocktime as outtime from outs

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Pete Helgren
Sent: Thursday, July 19, 2012 4:54 PM
To: Midrange Systems Technical Discussion
Subject: Re: SQL scrolling back to a record - REVISTED

I ended up with this as an executable query :

with tbl as (select emp,
char(tim)|| ' ' || char(dte) as clocktime,punch from timecard A) , ins as (select * from tbl where punch='IN') , outs as (select * from tbl where punch='OUT') select outs.emp, (select min(ins.clocktime) from ins where ins.emp = outs.emp and ins.clocktime > outs.clocktime) as intime, outs.clocktime as outtime from outs

The cast to an actual timestamp was problematic because of the format of the data. But, the results were a little wonky....

EMP INTIME OUTTIME
3,333 - 10:15:00 05/17/12
1,111 22:20:00 05/17/12 10:20:00 05/17/12
1,111 09:05:00 05/16/12 04:07:00 05/18/12
1,111 - 22:20:00 05/18/12
2,222 09:10:00 05/17/12 06:20:00 05/19/12
2,222 22:20:00 05/18/12 20:20:00 05/19/12

I am going to pursue the solution Charles gave me but I am still hanging on to this approach because it seems to some merit as well. Just have to sort out the particulars.

Pete Helgren
Value Added Software, Inc
www.petesworkshop.com
GIAC Secure Software Programmer-Java

On 7/19/2012 2:22 PM, Dan Kimmel wrote:
Why not use timestamp arithmetic and an embedded query?

with tbl as (select emp, timestamp(tim || ' ' || dte) as clocktime
from timecard A) tbl , ins as (select * from tbl where punch='IN') ,
outs as (select * from tbl where punch='OUT') select outs.emp,
outs.clocktime as outtime, (select min(ins.clocktime) from ins where
ins.emp = out.emp and ins.clocktime > outs.clocktime) as intime from
outs

I'm not sure about the arguments in that timestamp function, but the rest should work.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.