Access Query

Hi Guys

I am trying to write a query which can provide me Monthly Total depends on the user input date and year to date total also in the same query.

My table has the fields : Application Id, Status, Date.

My query should give an out put

Total Record In Oct-13  = 10
YTD Record  Till Oct-13 =  50 (will Add all from Jan-13 -Oct-13)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeCommented:
Something like the following should work.  BTW, you should not use [Date] as a field name in Access because it is a reserved name and must have brackets around it to represent the field (it conflicts with the Date() function).

SELECT Sum(iif(Format([Date]), "mmyy") = [YourDate], 1, 0) as MonthCount,
             Sum(iif(Format([Date]), "yy") = Right([YourDate], 2), 1, 0) as YearCount
FROM YourTable
surah79Author Commented:
Hi Fyed,

Its giving me an error function has wrong number of arguments.
SELECT Sum(iif(Format([ Decision Date]), "mmyy") = [YourDate], 1, 0) as MonthCount,
             Sum(iif(Format([Decision Date]), "yy") = Right([YourDate], 2), 1, 0) as YearCount
FROM Application
where status = 3;

Open in new window

Dale FyeCommented:
Sorry, had an extra right ) in each of the Format statements.  Try:

SELECT Sum(iif(Format([ Decision Date], "mmyy") = [YourDate], 1, 0) as MonthCount,
             Sum(iif(Format([Decision Date], "yy") = Right([YourDate], 2), 1, 0) as YearCount
FROM Application
where status = 3;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.