jbradleyharris
Programmer
I built a query against a SQL server to pull information about accounts that have multiple records in 2008. Now I need to isolate the accounts where those multiple records fall within five days of eachother. I'm no database programmer. I think I should be able to do something with DateAdd to figure this out but so far I'm drawing a blank as to just how to go about it. I would greatly appreciate it if someone could help me out with this. Here is my original query:
Where do I go from here?
Code:
[b][blue]
SELECT IMEV_ACS.dbo.IMAGERECORDS.RECID,
IMEV_ACS.dbo.IMAGERECORDS.DATEADDED,
IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER,
IMEV_MASTER.dbo.IMAGEPATHS.FolderName
FROM IMEV_MASTER.dbo.IMAGEPATHS INNER JOIN
IMEV_ACS.dbo.IMAGERECORDS ON IMEV_MASTER.dbo.IMAGEPATHS.PATHID = IMEV_ACS.dbo.IMAGERECORDS.PATHID
WHERE (LEN(IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER) = 16)
AND (IMEV_ACS.dbo.IMAGERECORDS.DATEADDED BETWEEN '2008-01-01' AND '2009-01-01')
AND (IMEV_ACS.dbo.IMAGERECORDS.UNIT LIKE 'Fee Disput%'
OR IMEV_ACS.dbo.IMAGERECORDS.UNIT LIKE 'OHIO%'
OR IMEV_ACS.dbo.IMAGERECORDS.UNIT = 'EXE CORR'
OR IMEV_ACS.dbo.IMAGERECORDS.UNIT = 'EXE CORR COMPLTS')
AND IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER IN
(SELECT IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER
FROM IMEV_ACS.dbo.IMAGERECORDS
WHERE (LEN(IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER) = 16)
AND (IMEV_ACS.dbo.IMAGERECORDS.DATEADDED BETWEEN '2008-01-01' AND '2009-01-01')
AND (IMEV_ACS.dbo.IMAGERECORDS.UNIT LIKE 'Fee Disput%'
OR IMEV_ACS.dbo.IMAGERECORDS.UNIT LIKE 'OHIO%'
OR IMEV_ACS.dbo.IMAGERECORDS.UNIT = 'EXE CORR'
OR IMEV_ACS.dbo.IMAGERECORDS.UNIT = 'EXE CORR COMPLTS')
GROUP BY IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER
HAVING Count(IMEV_ACS.dbo.IMAGERECORDS.ACCOUNT_NUMBER)>1)
[/blue][/b]