Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8096207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:22:42+00:00 2026-06-05T21:22:42+00:00

Any Access guru’s out there that can help me out? Trying to figure out

  • 0

Any Access guru’s out there that can help me out? Trying to figure out how to achieve the following: I want a query to go through each individual in the table of individuals and return those who have a true value in Christmas List field. This database is old and was created with the CompanyName as the primary key for table of companies (I know – bad design). To get around having a company with multiple locations they created an addressline field. That way if “Company y” opens a new location in San Diego, they add an entry of “Company Y – San Diego” and enter “Company Y” in the addressline. Then for individuals who don’t have a company, they are entered in a dummy company entry of “Home”. So ideally, what I want this query to do is to loop through, grab all the individuals who are supposed to be on the Christmas List, If the addressline field ISN’T NULL I want CompanyName to equal the AddressLine, but If CompanyName = “Home” I want CompanyName to equal “” (emptry string). Also some people have a overnight address, since their normal address is a P.O Box. The below query I have working for me mostly, however I am not clear on how to make the companyname blank in the returned results if CompanyName=”Home”.

SELECT tblIndividuals.FirstName, tblIndividuals.LastName, IIf([tblcompanies].[addressline] Is Not Null,[tblcompanies].[addressline],[tblcompanies].[companyname]) AS CompanyName, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[MailingAddress1],[tblIndividuals].[MailingAddress1]) AS MailingAddress1, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[MailingAddress2],[tblIndividuals].[MailingAddress2]) AS MailingAddress2, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[MailingAddress3],[tblIndividuals].[MailingAddress3]) AS MailingAddress3, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[MailingAddress4],[tblIndividuals].[MailingAddress4]) AS MailingAddress4, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[City],[tblIndividuals].[City]) AS City, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[State],[tblIndividuals].[State]) AS State, IIf([tblIndividuals].[MailingAddress1] Is Null,[tblCompanies].[Zip],[tblIndividuals].[Zip]) AS Zip
FROM tblIndividuals INNER JOIN tblCompanies ON tblIndividuals.CompanyName = tblCompanies.CompanyName
WHERE (((tblIndividuals.ChristmasList)=True))
Order by [tblIndividuals].[companyname];

I would love to have it sort by CompanyName Values (A-Z), THEN by Individual’s last names (A-Z) if at all possible. I will not pretend to be great at SQL, so any help you could give me would be hugely appreciated. Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:22:47+00:00Added an answer on June 5, 2026 at 9:22 pm

    Consider a UNION query, for example:

    SELECT i.FirstName, i.LastName, 
           IIf(c.[addressline] Is Not Null,
               c.[addressline],c.[companyname]) AS CompanyName, 
           c.[MailingAddress1] AS MailingAddress1, 
           c.[MailingAddress2] AS MailingAddress2, 
           c.[MailingAddress3] AS MailingAddress3, 
           c.[MailingAddress4] AS MailingAddress4, 
           c.[City] AS City, 
           c.[State] AS State,
           c.[Zip] AS Zip
    FROM tblIndividuals i
    INNER JOIN tblCompanies c ON i.CompanyName = c.CompanyName
    WHERE i.ChristmasList=True
    AND i.[MailingAddress1] Is Null
    UNION
    SELECT i.FirstName, i.LastName, 
           IIf(c.[addressline] Is Not Null,c.[addressline],
               c.[companyname]) AS CompanyName, 
           i.[MailingAddress1] AS MailingAddress1, 
           i.[MailingAddress2] AS MailingAddress2, 
           i.[MailingAddress3] AS MailingAddress3, 
           i.[MailingAddress4] AS MailingAddress4, 
           i.[City] AS City, 
           i.[State] AS State,
           i.[Zip] AS Zip
    FROM tblIndividuals i
    INNER JOIN tblCompanies c ON i.CompanyName = c.CompanyName
    WHERE i.ChristmasList=True
    AND i.[MailingAddress1] Is Not Null
    

    You can wrap the query in brackets to create a derived table that you can sort using the query design window.

    SELECT FirstName, LastName, etc 
    FROM ( <union query> ) As q
    Order by q.[companyname]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the life of me I can't figure out why I can't access any
I get the following exception when trying to access any nodes of a parsed
I want that when a non logged in user tries to access any controller
I mean, if I declare any access modifier in Java, that modifier can be
How can I prove that images were stolen from a website? Is there any
The following method does not access any shared variable. It is still not thread
Is there any way to access file's history using the data in the .svn
Are there any way to access or set iphone's alarm? Im assuming if this
I was just wondering if there are any access methods or rules to prevent
Is there any access control solution available for apps running in google app engine?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.