?
Solved

Access 2007 SQL Query

Posted on 2013-02-04
6
Medium Priority
?
264 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

771 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