Sandesh555
asked on
AND operator usage with IIF
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(Las t([tblEmai ls&Comment s].[Sent Date]),"mm/dd/yyyy"))) AS [Email Date], IIf(IsNull(Last(tblPCCComm entsOld.Ol dComments) ),0,CDate( Left(Last( tblPCCComm entsOld.Ol dComments) ,InStr(1,L ast(tblPCC CommentsOl d.OldComme nts)," ")-1))) AS [Comment Date], IIf([Email Date]>[Comment Date],[Email Date],[Comment Date]) AS [Date], IIf([Date]=0,'',CDate(Form at(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].[Poli cy Reference]) LEFT JOIN tblPCCCommentsOld ON tblPCCMain.PolicyRef = tblPCCCommentsOld.PolicyNu mber) LEFT JOIN qryPCCMain ON tblPCCMain.PolicyRef = qryPCCMain.PolicyRef
GROUP BY tblPCCMain.PolicyRef;
and here is teh error I am getting.
Thanks,
Sandesh.
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
FROM ((tblPCCMain LEFT JOIN [tblEmails&Comments] ON tblPCCMain.PolicyRef = [tblEmails&Comments].[Poli
GROUP BY tblPCCMain.PolicyRef;
and here is teh error I am getting.
Thanks,
Sandesh.
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.
Try placing your entire iif statement in the GROUP BY clause.
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.
Any new columns should be in aggregate functions or in the GROUP BY clause.
ASKER
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
better if you can upload a strip down version of your db
ASKER
Let me try that.. Given me some time... I will post back. :)
select Group By or whatever aggregate function is appropriate in the Total row, for all the columns you have in your query