Results 1 to 3 of 3
  1. #1
    DBNovice is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    2

    SQL query help...nested join needed?

    Hello,
    I was hoping for advice on a query that I am attempting to write. The manipulations involve changes to the "Locale" field where the "Name" code is the same. I need to be able to have a Locale code from 0001-0005 for each Name code. Where a Locale code is not present, then one will be created and given a Cash amount based on the "0099" code for that particular Name code.

    For example, the below sample from my table looks as follows:


    Name Locale Cash
    100A 0002 $1.23
    100A 0003 $5.00
    100A 0004 $0.23
    100A 0005 $4.98
    100A 0099 $2.22
    100B 0001 $0.53
    100B 0003 $9.01
    100B 0004 $3.26
    100B 0099 $2.75
    100C 0003 $3.32
    100C 0004 $8.01
    100C 0005 $4.62
    100C 0099 $1.05

    Below is how I would like my final display to appear with the new data in bold:

    Name Locale Cash
    100A 0001 $2.22
    100A 0002 $1.23
    100A 0003 $5.00
    100A 0004 $0.23
    100A 0005 $4.98
    100A 0099 $2.22
    100B 0001 $0.53
    100B 0002 $2.75
    100B 0003 $9.01
    100B 0004 $3.26
    100B 0005 $2.75
    100B 0099 $2.75
    100C 0001 $1.05
    100C 0002 $1.05
    100C 0003 $3.32
    100C 0004 $8.01
    100C 0005 $4.62
    100C 0099 $1.05

    As you can see, there are only three distinct Name codes in the table (100A, 100B, 100C). The missing Locale codes are basically being filled in by the data associated with the 0099 Locale code for that particular Name. For example, since Name = 100A was missing Locale = 0001, a new row with these values and the Cash amount for Locale = 0099 will be created.



    The queries that I'm working are starting to look like gibberish as my thought process seems to be spirling out of control. I think I should another table containing only a complete Locale column code range (from 0001-0005) to compare against the main table. I keep running into problems, however.

    This is something that needs to be done in Access. I would really appreciate any advice or nudge in the right direction. Thank you very much.

  2. #2
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    Code:
    Dim rSet as RecordSet
    Dim Fld as Field
    Dim DB as Database 
    
    Set DB = CurrentDB()
    set rSet = DB.OpenRecordSet("TableName")
    
    While Not rSet.EOF
    
        For Each Fld in rSet.Fields
    
             Insert whatver your want to do here
    
        Next
    rSet.MoveNext
    Wend
    http://social.msdn.microsoft.com/For...for-each-field

    I think that might help you figure out how to look for missing values via query and replace them with whatever you want. Hope this helps

  3. #3
    DBNovice is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    2
    Quote Originally Posted by Symlink View Post
    Code:
    Dim rSet as RecordSet
    Dim Fld as Field
    Dim DB as Database 
    
    Set DB = CurrentDB()
    set rSet = DB.OpenRecordSet("TableName")
    
    While Not rSet.EOF
    
        For Each Fld in rSet.Fields
    
             Insert whatver your want to do here
    
        Next
    rSet.MoveNext
    Wend
    http://social.msdn.microsoft.com/For...for-each-field

    I think that might help you figure out how to look for missing values via query and replace them with whatever you want. Hope this helps

    Thanks a lot for the input. I will give it a try. I appreciate it.

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

Similar Threads

  1. Simepl query needed to JOIN three tables
    By mameha1977 in forum Queries
    Replies: 2
    Last Post: 10-19-2012, 06:00 AM
  2. Nested Join Help?
    By sab in forum Access
    Replies: 1
    Last Post: 12-16-2011, 05:08 PM
  3. Outer Join Nested in Inner Join
    By Stevens7 in forum Queries
    Replies: 2
    Last Post: 10-19-2011, 01:34 PM
  4. Nested join problem
    By kman42 in forum Queries
    Replies: 2
    Last Post: 03-25-2011, 02:05 PM
  5. Returning correct rows in a join/nested query
    By goneaccessing in forum Queries
    Replies: 5
    Last Post: 03-03-2010, 12:21 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