Results 1 to 12 of 12
  1. #1
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41

    query for managing data


    hi..
    can you please tell me how to write a query for the following.

    this is the input file :

    Zone Code Sold By Dealer/Workshop/TASC Option
    E 11 dealer abc (dealer) 2+2
    E 11 workshop abc(workshop) 2+1
    S 13 dealer wer (dealer) 2+1
    S 12 dealer tyu(dealer) 2+2
    S 13 dealer wer (dealer) 2+2
    E 11 workshop abc(workshop) 2+2
    E 11 dealer abc( dealer) 2+2
    N 34 dealer jkl ( dealer) 2+2
    S 12 workshop tyu(workshop) 3+1
    S 13 dealer wer (dealer) 2+2
    W 45 workshop hjk( dealer) 2+2

    the required output file is as follows:

    Zone Code Dealer/Workshop/TASC dealer workshop
    E 11 abc 2 2
    S 13 wer 3 0
    S 12 tyu 1 1
    N 34 jkl 1 0
    W 45 hjk 1 0


    i would like to run a query to get the table 'output' from the table 'input'

    Thanks for your help in advance!

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just check out if below gives some guidelines :

    Query1
    Code:
    SELECT 
        myTable.Zone, 
        myTable.Code, 
        myTable.[Dealer/Workshop/TASC], 
        myTable.[Sold By], 
        Count(myTable.Option) AS CountOfOption
    FROM 
        myTable
    GROUP BY 
        myTable.Zone, 
        myTable.Code, 
        myTable.[Dealer/Workshop/TASC], 
        myTable.[Sold By];
    The Final Query
    Code:
    TRANSFORM Nz(Max([CountOfOption]), 0) AS TheNoOff
    SELECT 
        Query1.Zone, Query1.Code, Query1.[Dealer/Workshop/TASC]
    FROM 
        Query1
    GROUP BY 
        Query1.Zone, Query1.Code, Query1.[Dealer/Workshop/TASC]
    PIVOT 
        Query1.[Sold By];
    Thanks

  3. #3
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    hey..thanks but i dint get the 'pivot' part in the final query as in how do you actually implement it?

  4. #4
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    as in the query i create is in design mode...how do i make a query in vba mode

  5. #5
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Alternatively. check
    Code:
    TRANSFORM Nz(Count(myTable.Option),0) AS CountOfOption
    SELECT myTable.Zone, myTable.Code, myTable.[Dealer/Workshop/TASC]
    FROM myTable
    GROUP BY myTable.Zone, myTable.Code, myTable.[Dealer/Workshop/TASC]
    PIVOT myTable.[Sold By];
    Not in to VBA syntax.
    Let us wait for someone to come along.

    Thanks

  6. #6
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    umm...no i meant where do i put the code that you have given?

  7. #7
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Open a new query in Query Builder Design View.
    Open it in SQL View & copy paste the code after replacing it with appropriate Table name & Field names.
    Run it.
    If it runs OK, open in Design mode & see the structure & then test it thoroughly with dummy data.
    If it does not run OK, troubleshoot.

    Thanks

  8. #8
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    hey! thanks a lot..i think the first code itself works !

    however now i am having another problem...i would like the output to be saved in a table and i cant use this query as a make table query...

  9. #9
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    A small query,
    Why do you want to save the output in a table ?

    Thanks

  10. #10
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    Cause i will be further using this data for another query

  11. #11
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    If that is the reason, then there is no need to save the results to a table.
    You can use a query as source for another query.

    I don't know, if you tried my second code of a single query. Does it work ? If it works without any problem, better to use it, as less complicated.

    Thanks

  12. #12
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    the second code went into some problems, probably just syntax...but then i thought if the first one works and i am new to access, better use it

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

Similar Threads

  1. Managing a CPR class
    By DiPietro14 in forum General Chat
    Replies: 1
    Last Post: 02-06-2012, 06:02 PM
  2. Managing Inventory in Access
    By bushkanaka86 in forum Access
    Replies: 1
    Last Post: 11-25-2011, 08:31 PM
  3. Replies: 13
    Last Post: 10-26-2011, 03:49 AM
  4. Managing Point in Time
    By Stressed in forum Database Design
    Replies: 1
    Last Post: 03-09-2010, 07:55 AM
  5. Managing Point in Time
    By Stressed in forum Programming
    Replies: 0
    Last Post: 03-01-2010, 08:47 AM

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