2
votes

I'd like to rewrite this query for Microsoft Access 2003:


SELECT t1.PERSONID
       ,t1.CARDEVENTDATE
       ,MIN(t1.CARDEVENTTIME1) AS Intime
       ,MAX(t2.CARDEVENTTIME1) AS Outtime 

FROM (   SELECT PERSONID
                , CARDEVENTDATE
                , FUNCTIONKEY
                , CONVERT(VARCHAR(10), SUBSTRING(CARDEVENTTIME, 1, 2) + ':' + SUBSTRING(CARDEVENTTIME, 3, 2) + ':' + SUBSTRING(CARDEVENTTIME, 5, 2), 8) 
                 AS CARDEVENTTIME1  
         FROM T_CARDEVENT 
         WHERE      (FUNCTIONKEY = 'A')) AS t1 
         LEFT OUTER JOIN (SELECT PERSONID
                                 ,CARDEVENTDATE, CARDEVENTDAY, FUNCTIONKEY
                                 ,CONVERT(VARCHAR(10), SUBSTRING(CARDEVENTTIME, 1, 2) + ':' + SUBSTRING(CARDEVENTTIME, 3, 2) + ':' + SUBSTRING(CARDEVENTTIME, 5, 2), 8) 
                                  AS CARDEVENTTIME 
                      FROM T_CARDEVENT AS T_CARDEVENT_3) 
           AS t2 
           ON t1.PERSONID = t2.PERSONID 
           AND t1.CARDEVENTDATE = t2.CARDEVENTDATE   
           GROUP BY t1.PERSONID, t1.CARDEVENTDATE )

The above works in SQL Server, but in Access I've tried to run this query. It produces an error in convert.

How should I modify my query to suit Access 2003? What's the suitable equivalent for TSQL's Convert function in Access 2003?

2
Please format your query so that it isn't an unreadable blob.SLaks
If you want someone to convert your query for you(!), perhaps you could help the reader by at least formatting so that is readable.Mitch Wheat
There is no such thing as "SQL Server 2003".Heinzi
Did you delete your previous question ? If so, why and did you find the answer ?Edelcom
@Edelcom, I find the solution for that questionGopal

2 Answers

1
votes

The sample below may suit, if you use SQL Server compatible Syntax.

In t2, you appear to be missing 1 from CARDEVENTTIME, so I added it to give CARDEVENTTIME1. You also appear to have an extra bracket at the end.

SELECT t1.PERSONID
       ,t1.CARDEVENTDATE
       ,MIN(t1.CARDEVENTTIME1) AS Intime
       ,MAX(t2.CARDEVENTTIME1) AS Outtime 

FROM (   SELECT PERSONID
                , CARDEVENTDATE
                , FUNCTIONKEY
                , CDate(Mid(CARDEVENTTIME, 1, 2) + ':' + Mid(CARDEVENTTIME, 3, 2) + ':' + Mid(CARDEVENTTIME, 5, 2)) 
                 AS CARDEVENTTIME1  
         FROM T_CARDEVENT 
         WHERE      (FUNCTIONKEY = 'A')) AS t1 
         LEFT OUTER JOIN (SELECT PERSONID
                                 ,CARDEVENTDATE, CARDEVENTDAY, FUNCTIONKEY
                                  , CDate(Mid(CARDEVENTTIME, 1, 2) + ':' + Mid(CARDEVENTTIME, 3, 2) + ':' + Mid(CARDEVENTTIME, 5, 2)) 
                                  AS CARDEVENTTIME1
                      FROM T_CARDEVENT AS T_CARDEVENT_3) 
           AS t2 
           ON t1.PERSONID = t2.PERSONID 
           AND t1.CARDEVENTDATE = t2.CARDEVENTDATE   
           GROUP BY t1.PERSONID, t1.CARDEVENTDATE 
0
votes

Can you not use the normal Access function Str(...) ?

Update: Dont have Access here to try it, but isn't there a parameter which tells Access to just use the sql as pass throught (without modifying it) ?