Solved

Access 2007 SQL Query

Posted on 2013-02-04
6
250 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
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

932 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

17 Experts available now in Live!

Get 1:1 Help Now