Solved

another query question

Posted on 2016-10-28
7
56 Views
Last Modified: 2016-10-28
Hi Experts,
I have another query question.  I have a query below:
Cal/Dist: IIf([RMLOCATION] In ("Z (Dist 6)","H (Dist 6)","District 6x","District 6"),"District 6",IIf([RMLOCATION] In ("V (Dist 2)","District 2"),"District 2",IIf([RMLOCATION] In ("W (Dist 3)","G (Dist 3)","District 3"),"District 3",IIf([RMLOCATION] In ("X (Dist 4)","District 4"),"District 4",IIf([RMLOCATION] In ("Y (Dist 5)","District 5","Calendar87"),"District 5",IIf(Left([RMLOCATION],1)="C",[RMLOCATION]))))))

my question is how do I exclude the "calendar 87" on the IIf(Left([RMLOCATION],1)="C",[RMLOCATION]) since "Calendar 87 is included in the District 5 and I have to removed from the part of IIf(Left([RMLOCATION],1)="C",[RMLOCATION]).

Thanks,
0
Comment
Question by:urjudo
[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
  • 2
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41864318
it will be best if you create a table with all the combination that you want.
the query will then be very simple using a join to the combination table.
0
 

Author Comment

by:urjudo
ID: 41864339
all calendars are in one table
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41864349
<all calendars are in one table > what table? is there a relationship to this table and the other table in the query?

how about the other parts of your IIF() statements?
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:urjudo
ID: 41864384
SELECT IIf([RMLOCATION] In ("Z (Dist 6)","H (Dist 6)","District 6x","District 6"),"District 6",IIf([RMLOCATION] In ("V (Dist 2)","District 2"),"District 2",IIf([RMLOCATION] In ("W (Dist 3)","G (Dist 3)","District 3"),"District 3",IIf([RMLOCATION] In ("X (Dist 4)","District 4"),"District 4",IIf([RMLOCATION] In ("Y (Dist 5)","District 5","Calendar87"),"District 5",IIf(Left([RMLOCATION],1)="C",[RMLOCATION])))))) AS [Cal/Dist]
FROM tblCourtRoom
GROUP BY IIf([RMLOCATION] In ("Z (Dist 6)","H (Dist 6)","District 6x","District 6"),"District 6",IIf([RMLOCATION] In ("V (Dist 2)","District 2"),"District 2",IIf([RMLOCATION] In ("W (Dist 3)","G (Dist 3)","District 3"),"District 3",IIf([RMLOCATION] In ("X (Dist 4)","District 4"),"District 4",IIf([RMLOCATION] In ("Y (Dist 5)","District 5","Calendar87"),"District 5",IIf(Left([RMLOCATION],1)="C",[RMLOCATION])))))), tblCourtRoom.STATUS
HAVING (((tblCourtRoom.STATUS)="Active"));
0
 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41864390
how do I exclude the "calendar 87" on the IIf(Left([RMLOCATION],1)="C",[RMLOCATION])

The answer is - You Don't.  I believe in another post, I explained to you that the IIf() exits as soon as something falls into the final true path.

Your code isn't working because you have a typo.  There is no space between Calendar and 87 in the IIf()
0
 

Author Closing Comment

by:urjudo
ID: 41864398
Thanks!!! I did not see there is no space.  sorry
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 41864411
PS - I agree with Rey.  This type of a conversion is better done with a cross-reference table.  I'm sure you are going to end up with more than one query that includes this logic and the table solves the entire problem in a consistent way.  You just change the table to move/add groupings.  The default is handled in the query.

Select ..., IIf(IsNull(tblGroup.GroupName), tblCourtRoom.RMLOCATION, GroupName) As Group
From tblCourtRoom Left Join tblGroup On tblCourtroom.RMLOCATION = tblGroup.RMLOCATION
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

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 …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…

738 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