By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,397 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,397 IT Pros & Developers. It's quick & easy.

Where IIf and Datediff Statement

P: n/a
I'm pretty new at writing SQL on Access and I need some help writing a
datediff query. Say I have a table called tb_Dates with the following
records:

A B C
1 02/01/05 02/15/05 02/25/05
2 02/02/05 01/31/05 02/15/05
3 02/05/05 -------- 02/16/05
4 02/05/05 02/18/05 --------
5 03/01/05 02/01/05 03/16/05

If A < B then calculated the difference in the number of days between B
and C.
If A > B then calculated the difference in the number of days between A
and C.

The result should be:

1 10
2 13
3 --
4 --
5 15

Any assistance would be greatful.

Edwin

Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SELECT tb_Dates.a, tb_Dates.b, tb_Dates.c,
IIf([a]<[b],DateDiff("d",[b],[c]),DateDiff("d",[a],[c])) AS Diff
FROM tb_Dates;
a b c Diff
01/02/2005 15/02/2005 25/02/2005 10
02/02/2005 31/01/2005 15/02/2005 13
05/02/2005 16/02/2005
05/02/2005 18/02/2005
01/03/2005 01/02/2005 16/03/2005 15
Mark

<ed**************@citigroup.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm pretty new at writing SQL on Access and I need some help writing a
datediff query. Say I have a table called tb_Dates with the following
records:

A B C
1 02/01/05 02/15/05 02/25/05
2 02/02/05 01/31/05 02/15/05
3 02/05/05 -------- 02/16/05
4 02/05/05 02/18/05 --------
5 03/01/05 02/01/05 03/16/05

If A < B then calculated the difference in the number of days between B
and C.
If A > B then calculated the difference in the number of days between A
and C.

The result should be:

1 10
2 13
3 --
4 --
5 15

Any assistance would be greatful.

Edwin
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.