?
Solved

Any problems with nested expressions?

Posted on 2014-01-31
2
Medium Priority
?
209 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Usā€¦
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: ā€¦
Suggested Courses

777 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