tags:

views:

40

answers:

1

Using Access 2003

Query

SELECT t1.PERSONID       ,t1.CARDEVENTDATE
       ,MIN(t2.CARDEVENTTIME) AS Intime
       ,MAX(t3.CARDEVENTTIME) AS Outtime,
Min(t3.Cardeventtime) as BreakOut,
Max(t4.CardEventTime) as BreakIn 

FROM ( ( (  SELECT PERSONID
                , CARDEVENTDATE
                         FROM T_CARDEVENT ) as t1
 LEFT OUTER JOIN  (SELECT PERSONID
                                 ,CARDEVENTDATE,  FUNCTION
                                  , CARDEVENTTIME
                      FROM T_CARDEVENT  WHERE  (FUNCTION = 'A'))  as t2
 ON t1.PERSONID = t2.PERSONID 
           AND t1.CARDEVENTDATE = t2.CARDEVENTDATE)  LEFT OUTER JOIN  (SELECT PERSONID
                                 ,CARDEVENTDATE,  FUNCTION
                                  , CARDEVENTTIME
                      FROM T_CARDEVENT  WHERE  (FUNCTION = 'D'))  as t3
 ON t1.PERSONID = t3.PERSONID 
           AND t1.CARDEVENTDATE = t3.CARDEVENTDATE )  LEFT OUTER JOIN  (SELECT PERSONID
                                 ,CARDEVENTDATE,  FUNCTION
                                  , CARDEVENTTIME
                      FROM T_CARDEVENT  WHERE  (FUNCTION = 'B'))  as t4
 ON t1.PERSONID = t4.PERSONID 
           AND t1.CARDEVENTDATE = t4.CARDEVENTDATE )  LEFT OUTER JOIN  (SELECT PERSONID
                                 ,CARDEVENTDATE,  FUNCTION
                                  , CARDEVENTTIME
                      FROM T_CARDEVENT  WHERE  (FUNCTION = 'C'))  as t5
 ON t1.PERSONID = t5.PERSONID 
           AND t1.CARDEVENTDATE = t5.CARDEVENTDATE 

           GROUP BY t1.PERSONID, t1.CARDEVENTDATE 

When i run the above query, it was taking too much time to view the result, so times it was displaying error message as "not enough temp space in a memory"

There is any alternative way to make a query like this in access.

Need query help

+1  A: 

Your query is a mess ... I'm not sure what you intend to do .. so here are some wild guesses, in the form of an answer instead of comments .. but I can't format comments ..

since all your joins are left outer joins ..

I suggest you try and play with this:

select FUNCTION
     , PERSONID
     , min(cardeventdate)
     , max(cardeventdate)
  from T_CARDEVENT 
 where FUNCTION in ('A','B','C','D')
group by FUNCTION,PERSONID

PS: a group by on CARDEVENTDATE and min/max on same field don't make much sense (to me).

lexu
@Lexu, You are not understand my query, how it is working. I want to get ID, Date, Min(time) where function = A, max(time) where function = D, min(time) where function = B, max(time) where function = C. So my query will display ID, Date, Four type timing. My mentioned above query is working in sql. But in Access it was taking too much time.
Gopal
I did state, that I didn't understand what you tried to do :-) Your query IS written in SQL (I assume you mean SQL-Server?) .. the reason for the poor performance is the 'left outer' joins and possibly a lack of indices. Best to restructure the DB or use another approach.
lexu