I would like to select from a database those stores who did not have any activity(no one did not shop) for 5 days or more in the last 6 months. e.g KFC didn't have any customers Monday,Tuesday, Wednesday,Thursday and Friday.So the below code is for those customers who did not shop in the last 6 mths (Dec 2008 - 31st May 2009), for 5 days or more. I also want to show the days that were missing. The database that I am using do not store the days that no activity happened, so there would be a gap in the data eg KFC had activity on the 1st June but the next transaction happened on the 15th June. I would like the output from the query to show the followKFC 5-06-2009 15-06-2009So the below information would make it on the list because they had 5 or more consecutive days of no shopping(activity) and the period that the store did not have activity is displayed.Any Ideasselect distinct s.storeid,transactiondatefrom Stores sinner join ( select distinct storeid,transactiondate ,(select top 1 transactiondate from transaction where storeid=t.storeid and transactiondate < t.transactiondate and (transactiondate >= '20081201' and transactiondate < '20090601') order by transactiondate desc) as prevdate from transaction t where (transactiondate >= '20081201' and transactiondate < '20090601') )r on r.subsidiaryid=s.subsidiaryidwhere (transactiondate >= '20081201' and transactiondate < '20090601') and r.transactiondate >= dateadd(dd,datediff(dd,0,prevdate)+5,0)