Hi ,When i run this query i am getting only one record .The one with the comented policy id DLKB6663 alone comes here . I have almost 1o lakhs of records . How to make all the records to be displayed by satisfying the below conditons . As outer apply is causing a performace issue i tried this but not able to find the root cause why it fetches one record only . Could you please help how to get all the records to be displayed . Your help is highly appreciated .[code="plain"]SELECT DISTINCT dbo.Systems.SiteNumber, dbo.PolicyAudit.ID, dbo.PolicyAudit.PolicyID, CONVERT(VARCHAR(8), dbo.PolicyAudit.LastModifiedDate, 112), dbo.PolicyAudit.CoverStartDate, dbo.PolicyAudit.EmployerName, dbo.PolicyAudit.Branch, dbo.PolicyAudit.Workgroup, dbo.PolicyAudit.ProductCode, dbo.PolicyAudit.Lob, DATEDIFF(day,dbo.PolicyAudit.CoverStartDate,GETDATE()), dbo.PolicyAudit.ERNExemptFlagFROM dbo.Systems RIGHT OUTER JOIN dbo.PolicyAudit ON (dbo.PolicyAudit.SourceSystemID=dbo.Systems.ID) INNER JOIN ( SELECT Top 1 pa.HasERN as HasERN , pa.id as id, pa.PolicyID as PolicyID , pa.LastModifiedDate as DateSent , ERNExemptFlag as ERNExemptFlag FROM PolicyAudit pa where pa.Status=1 Order By pa.ID desc ) Derived_Table3 ON (Derived_Table3.id=dbo.PolicyAudit.ID and Derived_Table3.PolicyID=dbo.PolicyAudit.PolicyID and Derived_Table3.DateSent=dbo.PolicyAudit.LastModifiedDate) WHERE ( dbo.PolicyAudit.Status = 1 AND dbo.PolicyAudit.HasERN = 0 AND CASE WHEN dbo.Systems.FileTypeIndicator= 'C' THEN 'Current' WHEN dbo.Systems.FileTypeIndicator= 'H' THEN 'Historic' WHEN dbo.Systems.FileTypeIndicator= 'V' THEN 'Voidance' ELSE '' END IN ( 'Current','Voidance' ) AND Derived_Table3.HasERN IN ( 0 ) --AND --dbo.PolicyAudit.PolicyID='DLKB6663' )[/code]
↧