473,378 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

iif Concatenation of set day/month with year from another field

In an access query I am trying to concatenate the year from one field onto a set day/month.

Here is where I'm at:

ExpirationDate: IIf([expire-dt]>#08/31/2009#,("8/31/" & [xyear]),8/31/2009)

The ("8/31/" & [xyear]) part should result like 8/31/2014 as an example. [xyear] is a four digit year.

I'll apreciate any help.

Thanks - AnderJ86


Access 2002 SP3
Jul 6 '09 #1
9 3614
ChipR
1,287 Expert 1GB
You don't mention what problem you are having, but the third argument, 8/31/2009, is going to be treated as a number and division applied unless you use quotes. Parentheses around the second argument are not necessary.
Jul 6 '09 #2
Thanks ChipR I tried:

ExpirationDate:ExpirationDate: IIf([expire-dt]>#08/31/2009#,"8/31/" & [xyear],"8/31/2009")

It errored with " The expression you entered contains invalid syntax)
Jul 6 '09 #3
ChipR
1,287 Expert 1GB
Is your actual code all on one line, or on two lines? I can't see any other problems (assuming the ExpirationDate twice was a copy & paste issue).
Jul 6 '09 #4
Stewart Ross
2,545 Expert Mod 2GB
Ahh, easy for you to miss that you've repeated the name of the field twice, which Chip refers to:

ExpirationDate:ExpirationDate: IIf([expire-dt]>#08/31/2009#,"8/31/" & [xyear],"8/31/2009")

hence the error. Should be

ExpirationDate: IIf([expire-dt]>#08/31/2009#,"8/31/" & [xyear],"8/31/2009")

The syntax of the line is otherwise correct.

-S
Jul 6 '09 #5
Thanks ChipR I tried:

ExpirationDate: IIf([expire-dt]>#08/31/2009#,"8/31/" & [xyear],"8/31/2009")

It errored with " The expression you entered contains invalid syntax)

It is all on one line. The two ExpirationDate's was a typo. If the syntax is correct I will just keep tweeking it until it works. - Thanks
Jul 6 '09 #6
Stewart Ross
2,545 Expert Mod 2GB
There may be an issue with returning the date literal as a string in double quotes. It may look like a date, but it is not of the same type.

Date literals are referred to like this: #8/31/2009#

As the True clause in your IIF builds a date using the month and day as a literal followed by a year from another field, use the DateSerial function to build the date instead of using a date literal:

IIF([expire-dt]>#08/31/2009#, DateSerial([xyear], 8, 31), #08/31/2009#)

-S
Jul 6 '09 #7
The error this time said "you tried to execute a query that does not include the specified expresion ExpirationDate: IIf([expire-dt]>#08/31/2009#,DateSerial([xyear], 8, 31),#08/31/2009#) as part of the aggreget function."

I also tried changing the way [xyear] was created first I used Year[expire-dt]-365 then I changed it to xyear: DatePart("yyyy",[expire-dt]-365) both returned the correct yyyy but I don't know what data type it is.
Jul 6 '09 #8
Stewart Ross
2,545 Expert Mod 2GB
You'll need to repeat the IIF statement in the GROUP BY clause of your SQL statement. The simplest way to do so is to use the Access query editor, select the View, Totals option, and select Group By for the total of the computed IIF field.

It is not correct to hard-code 365 days into your year calculations - leap years will not be dealt with correctly. In any event there is no need to do so. The Year function can give you the year component of any date, but without knowing more about what you are trying to achieve I can't be certain about what you should be doing. Please advise.

-S
Jul 6 '09 #9
I appreciate all the help but I am putting this aside for now.

Thanks - AnderJ86
Jul 9 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hasanain F. Esmail | last post by:
Hi all, I sincerly thank you all in advance for your help to solve this problem. I have been trying to find a solution to this problem for sometime now but have failed. I am working on a...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
6
by: Burghew | last post by:
Hello, I generate invoices for my customers evry month. I want to keep a form which will allow the user to select the Month and Year through a combo and thus generate reports based on the month...
18
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
10
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
25
by: rekhasc | last post by:
hi...... Its very urgent.............. how can i take only the year and month part and it should save in the database in the month and year field separately......... when i enter the date in the...
5
by: Seb | last post by:
I want to count activity in a given month. I'm trying to do so with the linq code below however it reports: Error 1 'a' is inaccessible due to its protection level var ActivityByMonths = from a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.