Results 1 to 5 of 5
  1. #1
    technesurge is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    14

    Trying to reorganize data from 2 tables into 1

    Hello folks, new to access...

    My datalogger is writing to Access through 2 tables: FloatTable and StringTable.

    The column format for FloatTable is:


    Date, Tagname, Value (a number)

    The column format for StringTable is:
    Date, TagName, Value (a string)

    I want to combine the two tables by making a column for each TagName.


    For example, FloatTable looks like this:
    5/31 5pm, data1, 123
    5/31 5pm, data2, 456
    5/31 5pm, data3, 789

    and StringTable looks like this:
    5/31 5pm, string1, "Thanks"
    5/31 5pm, string2, "For Your"
    5/31 5pm, string3, "Help"


    I want to reorganize the data with appropriate field names so that it looks like this:

    date | string1 | string2 | string3 | data1 | data2 | data3
    -------------------------------------------------------------------------------------
    5/31 5pm "Thanks" "For Your" "Help" 123 456 789

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What are the field names of each table? I will use:
    MyDate MyTime MyData MyValue
    and
    MyDate MyTime MyString MyValue

    Try two crosstab queries then join the crosstabs on the MyDate and MyTime fields:
    TRANSFORM First([MyValue]) AS FirstOfMyValue
    SELECT [MyDate], [MyTime]
    FROM Table1
    GROUP BY [MyDate], [MyTime]
    PIVOT [MyData];

    TRANSFORM First([MyValue]) AS FirstOfMyValue
    SELECT [MyDate], [MyTime]
    FROM Table2
    GROUP BY [MyDate], [MyTime]
    PIVOT [MyString];

    Other methods to denormalize data and arrange left-to-right (horizontal):

    Review:
    http://forums.aspfree.com/microsoft-...ry-322123.html
    http://allenbrowne.com/func-concat.html

    Another method (seems I have dealt with this before in another thread) might be a query for each string and data then join them all on the date and time values.
    SELECT MyDate, MyTime, MyValue As Data1 WHERE MyData = data1
    SELECT MyDate, MyTime, MyValue As Data2 WHERE MyData = data2
    SELECT MyDate, MyTime, MyValue As Data3 WHERE MyData = data3
    SELECT MyDate, MyTime, MyValue As String1 WHERE MyData = string1
    SELECT MyDate, MyTime, MyValue As String2 WHERE MyData = string2
    SELECT MyDate, MyTime, MyValue As String3 WHERE MyData = string3
    Last edited by June7; 06-01-2012 at 05:41 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Be aware that "Date" and "Value" are reserved words in Access shouldn't be used for object names.


    Also, in the second crosstab query, I think "Table1" should be "Table2":
    Code:
    TRANSFORM First([MyValue]) AS FirstOfMyValue
    SELECT [MyDate], [MyTime]
    FROM Table2
    GROUP BY [MyDate], [MyTime]
    PIVOT [MyString];

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Yes, ssanfu, copy/paste strikes again! I have corrected my post, thanks.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    technesurge is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    14
    Outstanding, thank you both very much!

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

Similar Threads

  1. Replies: 5
    Last Post: 08-12-2013, 12:53 AM
  2. Replies: 5
    Last Post: 05-14-2012, 02:01 PM
  3. Replies: 4
    Last Post: 02-27-2012, 10:29 AM
  4. Replies: 14
    Last Post: 01-10-2012, 03:12 PM
  5. Reorganize fields
    By pollux in forum Queries
    Replies: 1
    Last Post: 07-15-2010, 03:04 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