0% found this document useful (0 votes)
112 views

Saha Script

This document contains the code for a stored procedure that retrieves data validation report information for items in a specified batch from various database tables. The stored procedure accepts a batch ID as a parameter. It selects various data fields for each batch item from the BatchItem table and joins to other tables to retrieve additional address and status description fields. It also includes logic to determine an overall status and status reason for each item based on the validation results.

Uploaded by

Raju Perumandla
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Saha Script

This document contains the code for a stored procedure that retrieves data validation report information for items in a specified batch from various database tables. The stored procedure accepts a batch ID as a parameter. It selects various data fields for each batch item from the BatchItem table and joins to other tables to retrieve additional address and status description fields. It also includes logic to determine an overall status and status reason for each item based on the validation results.

Uploaded by

Raju Perumandla
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

USE [SPDB]

GO
/****** Object: StoredProcedure [dbo].[GetBatchItemDataValidationReport]
ipt Date: 4/14/2016 5:06:35 PM ******/
SET ANSI_NULLS ON
GO

Scr

SET QUOTED_IDENTIFIER ON
GO
/*
USE [SPDB]
GO
--SPDB.dbo.GetBatchItemDataValidationReport
IF EXISTS (SELECT 1 FROM Sys.objects WHERE type = 'P' AND name = 'GetBatchItemDa
taValidationReport')
BEGIN
DROP PROCEDURE dbo.GetBatchItemDataValidationReport
PRINT 'Dropped & Created Procedure - dbo.GetBatchItemDataValidationRepor
t'
END
ELSE
BEGIN
PRINT 'Creating Procedure - dbo.GetBatchItemDataValidationReport'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

EXEC [dbo].[GetBatchItemDataValidationReport] @BatchId = 4


*/
CREATE PROCEDURE [dbo].[GetBatchItemDataValidationReport] (
@BatchId INT
)
AS
BEGIN
SELECT
BI.BatchItemId
,BI.BatchId
,BI.ReferenceId
,BI.APN
,BI.County
,BI.AddressLine
,BI.City
,BI.State
,BI.Zip
,BI.LoanDate

,BI.LoanAmount
,BI.BorrowerName
,BI.PropertyId
,BI.PreValStatusId
,BI.PreValErrorDesc
,BI.InCoverage
,BI.DataValStatusId
,BI.DataValErrorDesc
,BI.LoanDataStatusId
,BI.OrigLoanDocType
,BI.OrigLoanRecDate
,BI.OrigLoanValue
,BI.OrigLoanBorrowername
,BI.OrigLoanLenderName
,BI.BatchServerName
,BI.LenderName
,BI.OrigCMTId
,BI.OrigDocDescription
,[dbo].[GetFullSTDStreetAddress]
(
PT.StreetNumber
,PT.StreetDir
,PT.StreetName
,PT.StreetType
,PT.StreetPostDir
,PT.UnitType
,PT.Unit
) AS AddressLine_STD
,PT.City AS City_STD
,PT.State AS State_STD
,CONVERT(VARCHAR(10), PT.Zip5) AS Zip5_STD
,CONVERT(VARCHAR(10), PT.Zip9) AS Zip9_STD
--,PT.StreetNumber
--,PT.StreetDir
--,PT.StreetName
--,PT.StreetType
--,PT.StreetPostDir
--,PT.UnitType
--,PT.Unit
--,PT.AddressLine1
--,PT.AddressLine2
--,PT.FullTextSearchAddress
,ST.StatusDescription
,(
CASE BI.PreValStatusId
WHEN 1 THEN -- Pass, check other conditions
(
CASE /*Defined in Normandy.Shared.Batch.Enums.D
ataValidationResult*/
WHEN BI.DataValStatusId IS NULL OR BI.In
Coverage IS NULL THEN 'Error'
WHEN BI.InCoverage = 1 AND (BI.DataValSt
atusId = 2 /*NotFound*/ OR BI.DataValStatusId = 3) /*MultipleFound*/ THEN 'Rejec
ted'
WHEN BI.InCoverage = 0 AND BI.DataValSta
tusId = 1 /*Found*/ THEN 'Rejected'
ELSE 'Passed'
END
)
WHEN 2 THEN 'Rejected'

END
) AS [Status]
,BI.StatusId
,(
CASE BI.PreValStatusId
WHEN 1 THEN -- Pass, check other conditions
(
CASE /*Defined in Normandy.Shared.Batch.Enums.D
ataValidationResult*/
WHEN BI.DataValStatusId IS NULL OR BI.In
Coverage IS NULL THEN 'Error'
WHEN BI.InCoverage = 1 AND BI.DataValSta
tusId = 2 /*NotFound*/ THEN 'Property not found'
WHEN BI.InCoverage = 1 AND BI.DataValSta
tusId = 3 /*MultipleFound*/ THEN 'Multiple Properties Found'
WHEN BI.InCoverage = 0 AND BI.DataValSta
tusId = 1 /*Found*/ THEN 'Not in coverage'
ELSE ''
END
)
WHEN 2 THEN 'Invalid input data'
END
) AS [StatusReason]
--Invalid input data
--Not in coverage
--Property not found
--Multiple Properties Found
--''If Passed
FROM
NormandyBatch.dbo.BatchItem AS BI
LEFT JOIN
NormandySearch.Search.Property AS PT
ON BI.PropertyId = PT.PropertyId
LEFT JOIN
NormandyBatch.dbo.Status AS ST ON BI.StatusId = ST.StatusId
WHERE
BI.BatchId = @BatchId
ORDER BY
BI.BatchItemId
END -- End SP

GO

You might also like