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

x
?
Solved

Any problems with nested expressions?

Posted on 2014-01-31
2
Medium Priority
?
210 Views
Last Modified: 2014-02-05
Hello - is there a hard & fast rule about nested expressions in Access (2010) queries, like:
Sum(1) As CountOfTotalTickets, Sum(IIf([Hours] > 0,1,0)) As CountOfTicketsWithHours, [CountOfTicketsWithHours]/[CountOfTotalTickets] As PctTicketsWithHours

I know I could do this in a single expression, but this is just one simple example from a large set of qry's I have to work up where it gets more complicated than this.

Also, I'm trying to structure these qry's in a way that I can pull them up in datasheet view and demo that the math is being done correctly (a "show your  work" kind of thing)

On occasion, I have done this with no problems, and other times, it would get flaky on me.  

Thanks
0
Comment
Question by:mlagrange
[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
2 Comments
 
LVL 4

Accepted Solution

by:
Jack Leach earned 1000 total points
ID: 39824143
No issues other than readability.  Because of readability, sometimes things get a little flaky (especially with the query designer or SQL view, as the fonts are horrible for this type of stuff).

I tend to build SQL and expressions in Notepad++ using Poor Man's T-SQL formatter, then drop them into the SQL View of a query.  Having highlighting for opening/closing brackets and being able to see things monospaced and multi-line is a huge help for stuff like this.

As far as processing goes though, nope.  Just make sure your logic and arguments are correct.

Cheers,
-jack
0
 
LVL 15

Assisted Solution

by:JimFive
JimFive earned 1000 total points
ID: 39824148
If there is any ambiguity due to the names used in the calculation then it won't work.  It is safer to always just redo the calculation (Sum(1)/Sum(iif(hours>0,1,0))), or do the final calculation in the report/form control.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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 …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

604 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