It is my first question at stack overflow. I want to ask if there is any way I could make a field in an Access query which will be based on two other fields? Eg. in the following case, I want to make a field ReqDate in the query which will return DueDate + 1 year if products > 90, and DueDate + 6 months if products < 90.
Asked
Active
Viewed 85 times
2 Answers
1
As this is Access, the query could look like:
Select
*,
DueDate,
products,
IIf(products > 90, DateAdd("yyyy", 1, DueDate), DateAdd("m", 6, DueDate)) As ReqDate
From
YourTable;
or, if you like, a bit tighter:
Select
*,
DueDate,
products,
DateAdd("m", 6 * (Abs(products > 90) + 1), DueDate) As ReqDate
From
YourTable;

Gustav
- 53,498
- 7
- 29
- 55
-
Thanks alot for your help :) – Hira Iftikhar Jan 23 '16 at 14:59
0
To add date you can use the DATEADD function of sql server.
select ID, DueDate, products ,
(CASE
WHEN products > 90
THEN DATEADD(yy, 1, DueDate)
ELSE DATEADD(mm, 6, DueDate)
END) as ReqDate from table;
Links: