Skip to content

Instantly share code, notes, and snippets.

@saip106
Last active September 26, 2017 00:47
Show Gist options
  • Save saip106/073191a4a4e032e7d9eb83d9f9cb1dc1 to your computer and use it in GitHub Desktop.
Save saip106/073191a4a4e032e7d9eb83d9f9cb1dc1 to your computer and use it in GitHub Desktop.
select c.id, c.FirstName, c.LastName, c.LastModifiedDate, c.DateOfBirth, c.Gender, c.HomePhoneNumber, c.IsArchived, c.MiddleName, c.SSN,
a.StreetAddress as [Address], a.City, a.State, a.Zip, cl.ExternalId as ClientExternalId, cl.Name as ClientName
,(select top 1 value from Identifier where Identifier.ConsumerId = c.id and Identifier.IdentifierTypeId = @EmpiTypeId) as EmpiId
,(select top 1 value from Identifier where Identifier.ConsumerId = c.id and Identifier.IdentifierTypeId = @AbsentysTypeId) as AbsentysId
from Consumer c
inner join Address a on a.ConsumerId = c.Id
inner join Client cl on cl.Id = c.ClientId
where c.id in
(
select distinct max(C.Id) from Consumer c
inner join Identifier i on i.ConsumerId = c.Id
inner join Client cl on cl.Id = c.ClientId
where i.IdentifierTypeId = @AbsentysTypeId
group by cl.ExternalId+'-'+i.Value
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment