Results 1 to 10 of 10
  1. #1
    charlescdean is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    5

    SQL code: modifying a query to have multiple column headings

    Hello,

    I am new to Microsoft Access 2010 and have recently learnt how to create queries, crosstab queries and basic SQL coding.

    However I am trying to convert the data from this format:

    Country_name Major_product Main_product Species_group Species Sub_product Value ($)
    Latvia Wood Logs Softwood Other Sawlogs 0
    Honduras Wood Logs Softwood Other Sawlogs 0
    France Wood Logs Softwood Other Sawlogs 0
    Belgium Wood Logs Softwood Other Sawlogs 0
    Germany Wood Logs Softwood Other Sawlogs 0
    Finland Wood Logs Softwood Pine O/T sawlogs 7700
    Sweden Wood Logs Softwood Pine O/T sawlogs 6611
    Ireland Wood Logs Softwood Pine O/T sawlogs 1972
    Latvia Wood Logs Softwood Pine O/T sawlogs 848
    France Wood Logs Softwood Pine O/T sawlogs 49

    Into the following format:



    Major_product Wood
    Main_product Logs
    Species_group Softwood
    Species Other Pine
    Sub_product Sawlogs O/T sawlogs
    Country_name
    Latvia 0 848
    France 0 49
    Honduras 0
    Belgium 0
    Germany 0
    Finland 7700
    Sweden 6611
    Ireland 1972

    Is this possible? I have ~ 4000 entries so it would take too long to organise this manually. I have quite a lot of programming experience, but am relatively new to Access / SQL. I imagine this wouldn't be possible using the simple query wizard. I expect it will take some SQL code - I would be very grateful if anyone might know how to perform this operation and are willing to share this information.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    Just build a few 'make table' queries.
    That 1st one would be
    select DISTINCT Major_product,main, spec_grp, species, subprod INTO tCata from table

    key the fields needed.
    then do the same for other tables to be made.

  3. #3
    charlescdean is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    5
    Thankyou for the reply - I've figured out how to build 'make table' queries.

    but I'm going to need you to help me with the coding if that's okay.

    What is tCata?

    Can you provide more details on the exact syntax, as it will take me forever to figure this out on my own (if ever!)

    Thanks,

  4. #4
    charlescdean is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    5
    I tried what you suggested but got the

    "Query input must contain at least one table or query"

    error message.

    Tried different code but can't get past this message.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    you didnt supply table names, so I made 'em up.

    qry error: put a table in the query above the grid.

  6. #6
    charlescdean is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    5
    above which grid?

    when i put in the code you suggest with the table name (table name is 'multiple_headings') I get:

    "Syntax error in FROM clause."

    Any ideas what I'm doing wrong?

  7. #7
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    The query grid. Send a picture of your query design in the query grid.

  8. #8
    charlescdean is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    5
    Here is the screenshot:
    Click image for larger version. 

Name:	screenshot.jpg 
Views:	7 
Size:	109.6 KB 
ID:	18396


    I'm not a dilbert in real life - just never used access before and trying to meet a deadline! Your help will be much appreciated.

  9. #9
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    It may not like your naming....use letters not characters >,<!@#$%

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,953
    Good point ranman, should avoid spaces and special characters/punctuation (underscore is only exception) in naming convention, even though Access will accept them they can cause frustration. If they are used, make sure to enclose names in [] in queries and code. Access will try but sometimes will be confused by special characters and fail to add in the [].

    Consider instead of making tables, building a report using Grouping and Sorting features with aggregate calcs in footer section.
    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.

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

Similar Threads

  1. Variable Column Headings
    By asparks16 in forum Queries
    Replies: 1
    Last Post: 06-28-2012, 07:58 PM
  2. Replies: 2
    Last Post: 03-16-2012, 06:49 AM
  3. csv import second row contains column headings
    By dr_patso in forum Import/Export Data
    Replies: 1
    Last Post: 07-16-2011, 03:56 PM
  4. Resizing column headings
    By allykid in forum Access
    Replies: 0
    Last Post: 03-10-2011, 12:58 PM
  5. Cross Tab Column Headings...
    By mhoctober in forum Queries
    Replies: 3
    Last Post: 09-10-2010, 01:21 PM

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