Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Manipulating Dates In SQL Server

$
0
0

It's been a while and I have another issue that popped up.

I've been tasked to create an analysis of members who have visited an office less than thirty days after their last visit.

So, it's like this; I have a table with Mbr_ID, Visit_Date, Visit_Purpose.

There are several thousand Mbr_IDs and each have multiple Visit_Date entries with associated Visit_Purpose entries. However, for this, Vist_Purpose is irrelevant.

The task is to select all visits in 2012 (easily accomplished and already done) and then to retrieve only those members with a visit date 30 days or less than the prior visit and the date of that <=30-day visit.

I am unsure of how to grab Visit(n), check to see if Visit(n+1) is 30 or fewer days later, flag it and then increment n by 1 and do it over again.

Here's a flow chart to show the gist of what I'm after;

Any thoughts?

Thanx in advance!


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>