The XML:
<?xml version="1.0"?>-<ns0:usp_Moodlerooms_Cache_GetResponse xmlns:ns0="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/BizTalk" xmlns:ns3="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_Moodlerooms_Cache_Get" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<?xml version="1.0"?>-<ns0:usp_Moodlerooms_Cache_GetResponse xmlns:ns0="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/BizTalk" xmlns:ns3="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_Moodlerooms_Cache_Get" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<ns0:StoredProcedureResultSet0>
-<ns3:StoredProcedureResultSet0><ns3:SSO_UserId>3632303</ns3:SSO_UserId><ns3:SSO_UserName>maveales@yahoo.com</ns3:SSO_UserName><ns3:UserName>maveales@yahoo.com</ns3:UserName><ns3:FirstName>Mave</ns3:FirstName><ns3:MiddleName>Bent</ns3:MiddleName><ns3:LastName>Moras</ns3:LastName><ns3:EmailAddress>maveales@yahoo.com</ns3:EmailAddress><ns3:City>Esta City</ns3:City><ns3:Country>Philippines</ns3:Country><ns3:CompetenceName>0089 - Medical Care</ns3:CompetenceName><ns3:Abbreviation>CBT89</ns3:Abbreviation><ns3:VesselName>SKY WATER</ns3:VesselName><ns3:Rank>Manager</ns3:Rank><ns3:Customer>Magsaysay</ns3:Customer><ns3:DateOfBirth>1985-09-10T00:00:00Z</ns3:DateOfBirth><ns3:SeafarerNo>1993895</ns3:SeafarerNo></ns3:StoredProcedureResultSet0></ns0:StoredProcedureResultSet0><ns0:ReturnValue>1</ns0:ReturnValue></ns0:usp_Moodlerooms_Cache_GetResponse>
T SQL Script:
;WITH XMLNAMESPACES('http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/BizTalk/usp_Moodlerooms_Cache_Get' as ns3
UPDATE mrc SET
[SSO_UserName] = y.SSO_UserName
,[UserName] = y.UserName
,[FirstName] = y.FirstName
,[LastName] = y.LastName
,[MiddleName] = y.MiddleName
,[EmailAddress] = y.EmailAddress
,[City] = y.City
,[Country] = y.Country
,[CompetenceName] = y.CompetenceName
,[Abbreviation] = y.Abbreviation
,[Status] = NULL
,[VesselName] = y.VesselName
,[Customer] = y.Customer
,[Rank] = y.[Rank]
,[DateOfBirth] = y.DateOfBirth
,[IsSeafarer] = y.IsSeafarer
,[MRooms_UserId] = y.MRooms_UserId
,[MRooms_CourseId] = y.MRooms_CourseId
,[HasChanges] = y.HasChanges
,[UpdatedDate] = y.UpdatedDate
FROM
(SELECT
x.SSO_UserId
,x.SSO_UserName
,x.UserName
,x.FirstName
,x.MiddleName
,x.LastName
,x.EmailAddress
,x.City
,x.Country
,x.CompetenceName
,x.Abbreviation
,x.VesselName
,x.Customer
,x.[Rank]
,x.DateOfBirth
,x.SeafarerNo
,[IsSeafarer] = 1
,[MRooms_UserId] = (SELECT TOP 1 mc.[MRooms_UserId] FROM [dbo].[Moodlerooms_Cache] mc WITH (NOLOCK) WHERE mc.SSO_UserId = x.SSO_UserId)
,[MRooms_CourseId] = (SELECT TOP 1 mc.[MRooms_CourseId] FROM [dbo].[Moodlerooms_Cache] mc WITH (NOLOCK) WHERE mc.Abbreviation = x.Abbreviation AND mc.[MRooms_CourseId] IS NOT NULL )
,[HasChanges] = 1
,[CreatedDate] = @CurrentDateTime
,[UpdatedDate] = @CurrentDateTime
FROM
(SELECT
col.value('data(ns3:SSO_UserId[1])', 'int') as SSO_UserId
,col.value('data(ns3:SSO_UserName[1])', 'nvarchar(300)') as SSO_UserName
,col.value('data(ns3:UserName[1])', 'nvarchar(max)') as UserName
,col.value('data(ns3:FirstName[1])', 'nvarchar(50)') as FirstName
,col.value('data(ns3:MiddleName[1])', 'nvarchar(30)') as MiddleName
,col.value('data(ns3:LastName[1])', 'nvarchar(40)') as LastName
,col.value('data(ns3:EmailAddress[1])', 'nvarchar(max)') as EmailAddress
,col.value('data(ns3:City[1])', 'nvarchar(50)') as City
,col.value('data(ns3:Country[1])', 'nvarchar(50)') as Country
,col.value('data(ns3:CompetenceName[1])', 'nvarchar(300)') as CompetenceName
,col.value('data(ns3:Abbreviation[1])', 'nvarchar(20)') as Abbreviation
,col.value('data(ns3:VesselName[1])', 'nvarchar(250)') as VesselName
,col.value('data(ns3:Customer[1])', 'nvarchar(150)') as Customer
,col.value('data(ns3:Rank[1])', 'varchar(150)') as Rank
,col.value('data(ns3:DateOfBirth[1])', 'varchar(30)') as DateOfBirth
,col.value('data(ns3:SeafarerNo[1])', 'varchar(10)') as SeafarerNo
FROM
@XmlDataAltered.nodes('/usp_Moodlerooms_Cache_GetResponse/StoredProcedureResultSet0/ns3:StoredProcedureResultSet0') tbl(col)) x) y
Comments
Post a Comment