Solved

Any problems with nested expressions?

Posted on 2014-01-31
2
195 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
2 Comments
 
LVL 4

Accepted Solution

by:
Jack Leach earned 250 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 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 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

18 Experts available now in Live!

Get 1:1 Help Now