Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ageing of records

Status
Not open for further replies.

nread

Technical User
Oct 31, 2001
58
GB
Morning/Afternoon all...

Can some one tell me how i can age records,

I have 4 years worth of data which needs to be flagged into 4 categories:

3-6 mths
6-12 mths
>12 mths old.

I then need to apply a set of rules to the above.

Thought i could use something like

(MONTH(traffic_month) = MONTH(GETDATE())-2) OR
( MONTH(traffic_month) = MONTH(GETDATE())-3) OR
( MONTH(traffic_month) = MONTH(GETDATE())-4)

but hit problems when moving across years....

Any help greatfully received.

Cheers
 
Two ways:
Code:
-- first
WHERE getdate() - traffic_month BETWEEN <lowDays> AND <highDays>
-- second
DATEDIFF(mm, traffic_month, getdate()) BETWEEN <lowMonths> AND <highMonths>

First method is kind of approximate because months have different number of days.
Second method looks OK, but note that difference between Mar 01 and Feb 28 is 1 that way.

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top