Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Add two proc Logic in to single query - Help needed

$
0
0
The requirement for report was to display the Policy as per below logic. PROCEDURE [dbo].[spExceptionReport] @Month int, -- Should be a value from 1 to 12 (Not being used now) @Year int -- Should be 4 digit year number (Not being used now) AS BEGIN SET NOCOUNT ON; SELECT Distinct Systems.SiteNumber AS 'SiteNumber', PolicyAudit.PolicyID AS 'PolicyID', PolicyAudit.ERNExemptFlag AS 'ERNExemptFlag', CONVERT(VARCHAR(8), PolicyAudit.LastModifiedDate, 112) AS 'DateSent' FROM Systems LEFT JOIN PolicyAudit ON Systems.ID = PolicyAudit.SourceSystemID WHERE PolicyAudit.Status = 1 AND PolicyAudit.HasERN = 0 AND Systems.FileTypeIndicator in ('C','V') END We iterate through all the records which we receive from above query. Then for each policy, we fetch “HasERN” field as per following procedure logic. PROCEDURE [dbo].[spHelperProcedureERNExceptionReport] @PolicyID varchar (30) AS BEGIN SELECT Top(1) [HasERN], PolicyAudit.PolicyID AS 'PolicyID', CONVERT(VARCHAR(8), PolicyAudit.LastModifiedDate, 112) AS 'DateSent', Systems.SiteNumber AS 'SiteNumber', PolicyAudit.ERNExemptFlag AS 'ERNExemptFlag' FROM PolicyAudit Left Join [Systems] on PolicyAudit.SourceSystemID = [Systems].ID WHERE rtrim(ltrim(PolicyID)) = @PolicyID And Systems.FileTypeIndicator in ('C','V') And [Status] = '1' Order By PolicyAudit.ID desc END If the Policy’s HasERN status comes out as false =0 then we display it in the report. Could you please throw some light on this .

Viewing all articles
Browse latest Browse all 3145

Trending Articles