if in a query

  • Thread starter Thread starter joao
  • Start date Start date
J

joao

Hi,

is it possible to include an if then else in a query? I would like t
make te following:

"select if(datepart("yyyy",date.date)=2004 then month
datepart("m",date.date) + 12) as month from date;"

or something like that....

Thank
 
I'm not too sure if this is what you want, but it might help -

Select [Date]
From

Where [Date] like "*2004"

or something like

UPDATE tblTableName
SET tblTableName.[Date]= "2004"
WHERE [Date] like "*2004
 
not reallly,

i need to know if the year is 2004, and if it is, i will add 12 to th
a variable month that i will use to compare two dates. if the year i
2004, january would be month 13 (1 + 12), and if the year is 2003 the
january would be month 1.

any idea??
 
Yes, you use the IIf function. But you need a True and False result, and
your example only shows a True result. I've added in to use the Date field
from Date table if it's false. NOTE: Date, Month, etc. are not good to use
as names of tables, fields, controls, etc. Date and Month are VBA functions
and you can greatly confuse ACCESS! Use something such as MyMonth, MyDate,
WorkDate, etc.

SELECT IIf(DatePart("yyyy",[Date].[Date])=2004, DatePart("m",[Date].[Date])
+ 12), [Date].[Date]) AS [Month] FROM [Date];"
 
I think that you will not be able to have a month = 13 even if you hav
the correct syntax. Could you just add another year?

UPDATE
SET
.[Date] = datepart("yyyy", [date]) +1
WHERE
.[Date] Like "*2004"

or something similar?
 
Back
Top