Solved

Access 2007 SQL Query

Posted on 2013-02-04
6
245 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
  • 3
  • 2
6 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 500 total points
Comment Utility
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
Comment Utility
could you pl tell me how many trades you have?
0
 

Author Comment

by:squidlings
Comment Utility
Around 80-100 mark...

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

Thanks
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
-->> 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now