Results 1 to 5 of 5
  1. #1
    Atif Mahmood is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    May 2016
    Posts
    2

    Transpose Data of single table

    Hi all
    I have a table in which have these fields. Job No., StartDateTime & EndDateTime
    TimeDiffTbl

    581 04/03/2016 7:40:00
    581 04/03/2016 17:34:00
    581 04/04/2016 7:36:00
    581 04/04/2016 17:32:00


    581 04/05/2016 7:39:00
    581 04/05/2016 20:04:00
    581 04/06/2016 7:41:00
    581 04/06/2016 17:44:00
    i have all the data coming from excel file with only two columns , which have start time and end time in same column. i want my data with single date and starttime and endtime in one row.
    like Job No. / Date / Start time / End time so i can calculate the working hours. how can i do this , no idea.
    please help if some one understand what i am trying to ask
    thanks in advance

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    how do you tell if a time is a start time or an end time? - or is the assumption the first is a start, the second an end the third is a start etc? Or perhaps there is only on start and one end per day?

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    on reflection, you don't need to store the data in two columns. but can calculate from the single column

    Code:
    SELECT Table1.job, (SELECT MAX(enddt) FROM Table1 T WHERE Job=Table1.Job AND enddt<Table1.enddt and datevalue(enddt)=datevalue(table1.enddt) ) AS Started, Table1.enddt, [enddt]-[started] AS workhrs
    FROM Table1
    WHERE ((((SELECT MAX(enddt) FROM Table1 T WHERE Job=Table1.Job AND enddt<Table1.enddt and datevalue(enddt)=datevalue(table1.enddt) )) Is Not Null));
    Note this code may be varied depending on your answers to my first post

  4. #4
    Atif Mahmood is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    May 2016
    Posts
    2
    Quote Originally Posted by Ajax View Post
    how do you tell if a time is a start time or an end time? - or is the assumption the first is a start, the second an end the third is a start etc? Or perhaps there is only on start and one end per day?
    on the same date i think ascending order may solve the problem. First one will be the start time of the day and in between the next one will be breakout and then breakin and in last it will be end time. and may be there will be no breakout / in only start and end time.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    OK - well the code I suggested only allows for one start and one end per day

    This code will provide a time for each work period

    Code:
    SELECT Table1.job, (SELECT MAX(enddt) FROM Table1 T WHERE Job=Table1.Job AND enddt<Table1.enddt and datevalue(enddt)=datevalue(table1.enddt) ) AS Started, Table1.enddt, [enddt]-[started] AS workhrs
    FROM Table1
    WHERE ((((SELECT count(*) FROM Table1 T WHERE Job=Table1.Job AND enddt<Table1.enddt and datevalue(enddt)=datevalue(table1.enddt) ) Mod 2)<>0))
    and if you just want the total for each day, wrap it in a group by query

    Code:
    SELECT C.job, DateValue([enddt]) AS WorkDay, Sum(C.workhrs) AS SumOfworkhrs
    FROM (SELECT Table1.job, (SELECT MAX(enddt) FROM Table1 T WHERE Job=Table1.Job AND enddt<Table1.enddt and datevalue(enddt)=datevalue(table1.enddt) ) AS Started, Table1.enddt, [enddt]-[started] AS workhrs
    FROM Table1
    WHERE ((((SELECT count(*) FROM Table1 T WHERE Job=Table1.Job AND enddt<Table1.enddt and datevalue(enddt)=datevalue(table1.enddt) ) Mod 2)<>0)))  AS C
    GROUP BY C.job, DateValue([enddt])

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Transpose Data
    By jamesfranklin in forum Queries
    Replies: 15
    Last Post: 03-07-2013, 09:19 AM
  2. Transpose Data
    By Ray67 in forum Database Design
    Replies: 10
    Last Post: 08-07-2012, 06:18 PM
  3. Query to transpose Data in Columns to Rows
    By ace1259 in forum Access
    Replies: 2
    Last Post: 04-10-2012, 01:49 PM
  4. Transpose data in MS Access
    By JBLoafer in forum Access
    Replies: 12
    Last Post: 03-05-2012, 02:45 PM
  5. Replies: 3
    Last Post: 06-20-2011, 03:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums