Solved

AND operator usage with IIF

Posted on 2012-04-11
8
319 Views
Last Modified: 2012-04-12
Hi Team,

Using the link given below I am tring to use the AND operator in the IIF statement in Access query.  but it does not seem to work.  Is their a different way to using the AND opeartor in Access 2007.

http://windowssecrets.com/forums/showthread.php/13736-AND-operator-within-IIF-(Access-97) 

Please advise.  I have also attached the screen shot of the error I get when I try to run the code.

Here is the Query.
SELECT tblPCCMain.PolicyRef, IIf(IsNull(Last([tblEmails&Comments].[Sent Date])),0,CDate(Format(Last([tblEmails&Comments].[Sent Date]),"mm/dd/yyyy"))) AS [Email Date], IIf(IsNull(Last(tblPCCCommentsOld.OldComments)),0,CDate(Left(Last(tblPCCCommentsOld.OldComments),InStr(1,Last(tblPCCCommentsOld.OldComments)," ")-1))) AS [Comment Date], IIf([Email Date]>[Comment Date],[Email Date],[Comment Date]) AS [Date], IIf([Date]=0,'',CDate(Format(Now(),"mm/dd/yyyy"))-[Date]) AS Diff, First(qryPCCMain.Aging) AS Aging, First(qryPCCMain.[Due date]) AS [FirstOfDue date],IIF([Aging]='Not Yet Due','Not Yet due',IIF([Diff]='' AND [Due date]<>'Not Found','Need Update','')) as [Email Aging]
FROM ((tblPCCMain LEFT JOIN [tblEmails&Comments] ON tblPCCMain.PolicyRef = [tblEmails&Comments].[Policy Reference]) LEFT JOIN tblPCCCommentsOld ON tblPCCMain.PolicyRef = tblPCCCommentsOld.PolicyNumber) LEFT JOIN qryPCCMain ON tblPCCMain.PolicyRef = qryPCCMain.PolicyRef
GROUP BY tblPCCMain.PolicyRef;

and here is teh error I am getting.
Screen Shot
Thanks,
Sandesh.
0
Comment
Question by:Sandesh555
  • 3
  • 3
  • 2
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37833193
open your query in design view

select Group By or whatever aggregate function is appropriate in the Total row,  for all the columns you have in your query
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37833198
When you use aggregate functions such as FIRST, everything in your SELECT statement needs to appear either in an aggregate function or the GROUP BY clause.

Try placing your entire iif statement in the GROUP BY clause.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37833216
Fwiw, there is no difference between access 97 and 2007 on this respect.  I'm guessing that adding a new column caused the problem.

Any new columns should be in aggregate functions or in the GROUP BY clause.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:Sandesh555
ID: 37833271
Hi,

I have check the Goup By option and this is put under 'Expression'.  Now I tried to do some testing and the Query works perfectly if I remove the AND operator from the query.  It gives this error when I put back the AND operator.  I have done this several times now.

Thanks,
Sandesh.
0
 

Author Comment

by:Sandesh555
ID: 37833379
Hi Team,

I am also ok if you share with me a sample Query on how to solve the same using a sample data.  

I only want to know how to solve this techinically.  Resolving the attached query is given only for example.

thanks,
sandesh.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 37833433
this is a basic syntax


IIf([ShipRegion] Is Null And [ShipCountry]="Mexico","Yes","No")
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37833440
better if you can upload a strip down version of your db
0
 

Author Comment

by:Sandesh555
ID: 37833471
Let me try that.. Given me some time... I will post back. :)
0

Featured Post

Industry Leaders: 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

Title # Comments Views Activity
Union & Crosstab qrys 101! 6 52
Return Rows as per Quantity of Columns Value In SQL 6 26
Convert VBA UDF to SQl SERVER UDF 4 45
get and set file atrributes 5 8
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

679 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