SQL XML Queries examples
WITH XMLNAMESPACES ('http://www.meridianlink.com/CLF' as ns)
SELECT XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') as x,
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') as LoanStatus,
XMLData.query('/ns:VEHICLE_LOAN/ns:LOAN_STATUS') as xy,
FileName,FileParent
from ml.MeridianLinkData
WHERE XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') = 'N'
AND
(XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'APP' or
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'PRE-APP')
WITH XMLNAMESPACES ('http://www.meridianlink.com/CLF' as ns)
SELECT XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') as x,
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') as LoanStatus,
XMLData.query('/ns:VEHICLE_LOAN/ns:LOAN_STATUS') as xy,
FileName,FileParent
from ml.MeridianLinkData
WHERE XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') = 'N'
AND
(XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'APP' or
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'PRE-APP')
WITH XMLNAMESPACES ('http://www.meridianlink.com/CLF' as ns)
SELECT XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') as isDeclined,
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') as LoanStatus,
XMLData.query('/ns:VEHICLE_LOAN/ns:LOAN_STATUS') as LoanStatusXML,
XMLData.value('(/ns:VEHICLE_LOAN/ns:SYSTEM/ns:BRANCH/@name)[1]','varchar(50)') as BranchName,
XMLData.value('(/ns:VEHICLE_LOAN/ns:SYSTEM/ns:BRANCH/@reference_id)[1]','varchar(50)') as BranchNumber,
FileName,FileParent
from ml.MeridianLinkData
WHERE XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') = 'N'
AND
(XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'APP' or
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'PRE-APP')
AND XMLData.value('(/ns:VEHICLE_LOAN/ns:SYSTEM/ns:BRANCH/@name)[1]','varchar(50)') IS NOT NULL
WITH XMLNAMESPACES ('http://www.meridianlink.com/CLF' as ns)
SELECT x.BranchName, COUNT(x.AppCnt) AS TotalVL FROM (
SELECT XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') as AppCnt,
XMLData.value('(/ns:VEHICLE_LOAN/ns:SYSTEM/ns:BRANCH/@name)[1]','varchar(50)') as BranchName
from ml.MeridianLinkData
WHERE XMLData.value('(/ns:VEHICLE_LOAN/ns:APPLICANTS/ns:APPLICANT/@is_declined)[1]','varchar(50)') = 'N'
AND
(XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'APP' or
XMLData.value('(/ns:VEHICLE_LOAN/ns:LOAN_STATUS/@loan_status)[1]','varchar(50)') = 'PRE-APP')
AND XMLData.value('(/ns:VEHICLE_LOAN/ns:SYSTEM/ns:BRANCH/@name)[1]','varchar(50)') IS NOT NULL) AS x
GROUP BY x.BranchName
WITH XMLNAMESPACES ('http://www.meridianlink.com/CLF' as AWMI)
SELECT XMLData.query('/AWMI:CREDITCARD_LOAN/AWMI:SYSTEM') as x, FileName,FileParent
from MeridianXML
where cast(XMLData.query('/AWMI:CREDITCARD_LOAN/AWMI:SYSTEM') as varchar(max)) != ''
INSERT INTO ml.MeridianLinkData(XmlData,RowHash,SSISDate,FileDate,FileParent,FileName)
VALUES(
(SELECT *
FROM OPENROWSET(
BULK 'C:\Automation\MLDownload\Live\cc\CC_2098_OK.xml', SINGLE_BLOB) AS x),1231245877,'2015-1-1','2015-1-1','dfdfsd','sdfsdf')
GO
INSERT INTO MeridianXML(XmlData)
SELECT *
FROM OPENROWSET(
BULK 'C:\Xml\cc\503_ok.xml', SINGLE_BLOB)
AS ImportSource
GO
SELECT XMLData.query('
declare namespace AWMI="http://www.meridianlink.com/CLF";
/AWMI:CREDITCARD_LOAN/AWMI:SYSTEM/@loan_number
') as x
from MeridianXML
create view vw_test
as
SELECT XMLData.value('
declare namespace AWMI="http://www.meridianlink.com/CLF";
(/AWMI:CREDITCARD_LOAN/AWMI:SYSTEM/@loan_number)[1]
','varchar(50)') as LoanNumber,
XMLData.value('
declare namespace AWMI="http://www.meridianlink.com/CLF";
(/AWMI:CREDITCARD_LOAN/AWMI:LOAN_INFO/@is_complete_consumer)[1]
','varchar(50)') as LIComplete
from MeridianXML