Solved

Access 2007 SQL Query

Posted on 2013-02-04
6
261 Views
Last Modified: 2013-02-04
Hi,

I've got a little query on a query.

I have 1 big table, there is 1 field which is [text](key field) the rest are [yes/no]

Acc Number [text]
Electrician [yes/no]
plumber  [yes/no]
Joinery [yes/no]
.... lots and lots more

Basically I have this table of trades and I want the query to make their trades into Strings.

So if Acc number "1" is ticked for electrician and joinery, the query results will display, "electrician joinery" etc etc

Currently I'm doing this with 100's of IIF statements, Electrician2:iff([electrician]=yes,"Electrician","") then doing a concat of all of these results.

This works but takes ages and I'm sure there is a ...more intelligent efficient way to do what I'm trying to achieve :)

Any help appreciated.

Rich
0
Comment
Question by:squidlings
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 500 total points
ID: 38850588
The best way to do this if those trades are mutually exclusive is to have a single field whose options (drop-down list) are the trades you mention.

If that is not feasible another option (again assuming these are mutually exclusive options) without nested IIFs is to assign a value to each of those trades and do something like this:


Profession:  ABS(1 * [Electrician] + 2 * Plumber + 3 * Joinery ... etc)

Create a lookup table for those values and associated descriptions

1   Electrician
2   Plumber
3   Joinery

You could lookup the text based on the value on an as-needed basis...
0
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 38850620
could you pl tell me how many trades you have?
0
 

Author Comment

by:squidlings
ID: 38850636
Around 80-100 mark...

I understand I've structured this incorrectly.  However this was partly due to use convience...

Thanks
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38850764
I don't think there is any neat, concise way to do this.

Another way to handle this would be a huge UNION query:


SELECT x, y, z, "Electrician" AS Trade FROM YourTable WHERE Electrician = true
UNION
SELECT x, y, z, "Plumber" AS Trade FROM YourTable WHERE Plumber= true
UNION
SELECT x, y, z, "Joinery" AS Trade FROM YourTable WHERE Joinery = true

Etc...

Anyway you do this you are going to have to address each of the 80=100 trades in some way.
0
 

Author Closing Comment

by:squidlings
ID: 38850796
cool, thought as much, but was wondering if there may have been some sql looping sequence which may have worked.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38850820
-->> sql looping sequence

Not in Access SQL.  In a SQL Stored Procedure, perhaps.

Access also has the Switch function:

Switch(Electrician = True, "Electrician", Plumber= True, "Plumber", Joinery = True, "Joinery" ...)


Again a really ugly SQL statement, but a step up from nested IIFs.

You could probably create your own custom VBA function to do this as well....

But I don't know if this would help performance any.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question