Results 1 to 8 of 8
  1. #1
    bewsh1987 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Location
    UK
    Posts
    20

    Create a query and have the feild title repeat in the rows for a union all

    Hi All



    Need your help

    I am trying to create a union All query which I can do no problem example below

    What I need to do if possible is have the Title name as the row values i.e. [42337 Sales Volume] will show 42337 in the row values down for the first select statement then 42336 listed for the second select this will need a new column

    Please I need you expertise on this

    Thank you

    Code:
    SELECT "Week39" AS Week_No, [Week 39].[Retail Outlet Number], [Week 39].[Store Name], [Week 39].[Base Product Number], [Week 39].[Long Description], [Week 39].[42337 Sales Volume], [Week 39].[42337 Store Stock Volume], [Week 39].[42337 Store Stock Volume]
    FROM [Week 39];
    Union All
    SELECT "Week39" AS Week_No, [Week 39].[Retail Outlet Number], [Week 39].[Store Name], [Week 39].[Base Product Number], [Week 39].[Long Description], [Week 39].[42336 Sales Volume], [Week 39].[42336 Store Stock Volume], [Week 39].[42336 Store Stock Volume]
    FROM [Week 39];

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Are you looking for this type of thing?

    SELECT "Week39" AS Week_No, [42337 Store Stock Volume] AS 42337, 0 As 42336
    FROM [Week 39]
    UNION ALL
    SELECT "Week39" AS Week_No, 0 AS 42337, [42336 Store Stock Volume] As 42336
    FROM [Week 39]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bewsh1987 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Location
    UK
    Posts
    20
    Thanks you for your reply

    if the title is "42337 Sales Volume" then I would like 42337 listed in the rows

    is this possible?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I guess I don't understand. Can you post some sample data and what you'd like the result to be?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why is [_____ Store Stock Volume] included twice?

    I think yes.

    SELECT "Week39" AS Week_No, [Retail Outlet Number], [Store Name], [Base Product Number], [Long Description], [42337 Sales Volume] AS SalesVolume, "42337" As SalesCode, [42337 Store Stock Volume] AS StockVol FROM [Week 39];
    UNION ALL
    SELECT "Week39", [Retail Outlet Number], [Store Name], [Base Product Number], [Long Description], [42336 Sales Volume], "42336", [42336 Store Stock Volume] FROM [Week 39];

    If you normalized data structure, this UNION query would not be necessary.


    Also, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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.

  6. #6
    bewsh1987 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Location
    UK
    Posts
    20
    The data titles are from excel which is in pivot form the data is scraped as a pivot and I cannot get this in a listed format due to the amount of cells/data ( long story)

    I am working with 8 weeks of data each day is 27000 lines one select line is one day and the 42337 is a date formatted to 29/11/2015

    the union is well needed my purpose of this is to unpivot data with the tools I have without throwing a lot of formula in excel

    SELECT "Week39" AS Week_No, [Week 39].[Retail Outlet Number], [Week 39].[Store Name], [Week 39].[Base Product Number], [Week 39].[Long Description], [Week 39].[42337 Sales Volume], [Week 39].[42337 Store Stock Volume], [Week 39].[42337 Store Stock Volume]


    Pivot Data example

    Retail Outlet Number
    Store Name
    Base Product Number
    Long Description
    42295 Sales Volume
    42295 Store Stock Volume
    42294 Sales Volume
    42294 Store Stock Volume
    5
    Tesco BOLTON
    60183198
    MASC
    1
    3
    1
    4
    5
    Tesco BOLTON
    61576665
    VOLUME CLUBBING
    1
    3
    1
    4


    New Data access query example ( I can do this without the date no problem)
    Week_No Retail Outlet Number Store Name Base Product Number Long Description Sales Volume Store Stock Volume Date
    Week 33 5 Tesco BOLTON 60183198 MASC 1 3 42295
    Week 33 5 Tesco BOLTON 61576665 VOLUME CLUBBING 1 3 42295
    Week 33 5 Tesco BOLTON 60183198 MASC 1 4 42294
    Week 33 5 Tesco BOLTON 61576665 VOLUME CLUBBING 1 4 42294

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    This is resolved?
    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.

  8. #8
    bewsh1987 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Location
    UK
    Posts
    20
    In a long winded way yes I will be

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

Similar Threads

  1. Ignore blank rows in a UNION ALL query
    By Access_Novice in forum Queries
    Replies: 1
    Last Post: 12-20-2014, 08:36 PM
  2. Replies: 7
    Last Post: 01-16-2014, 09:17 AM
  3. Replies: 30
    Last Post: 08-15-2012, 02:25 PM
  4. Replies: 3
    Last Post: 12-09-2011, 11:55 AM
  5. Create table out of union query
    By DKruse1969 in forum Queries
    Replies: 2
    Last Post: 08-28-2009, 09:55 AM

Tags for this Thread

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