Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2007 SQL Query

Posted on 2013-02-04
6
Medium Priority
?
266 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

610 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