Skip to content

Instantly share code, notes, and snippets.

@ebot
Created January 26, 2010 19:09
Show Gist options
  • Save ebot/287109 to your computer and use it in GitHub Desktop.
Save ebot/287109 to your computer and use it in GitHub Desktop.
Select e.EncounterNo, e.EncntrStartDate, EncntrType, EncntrClass, IpOpInd
From Encounters as e
Left Outer Join #valid_encounters as ve on e.EncntrOwnerId = ve.EncntrOwnerId
Where e.EncntrStartDate >= '1/1/2000' and e.EncntrStartDate < '1/1/2010'
AND ve.EncntrOwnerId is null
Create Table #valid_encounters
(EncntrOwnerId bigint,
EncounterNo varchar(254),
EncntrStartDate smalldatetime)
Insert Into #valid_encounters
Select EncntrOwnerId, EncounterNo, EncntrStartDate
From DocTypes as dt
Inner Join Documents as d on dt.DocType = d.DocType
Inner Join DocsOwners as do on d.DocId = do.DocId
Inner Join Encounters as e on do.OwnerId = e.EncntrOwnerId
Where EncntrStartDate >= '1/1/2000' and EncntrStartDate < '1/1/2010'
AND DocTypeName = 'ACCTHSTY'
Group By EncntrOwnerId,EncounterNo, EncntrStartDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment