?
Solved

xquery working only for some columns/elements

Posted on 2014-10-23
2
Medium Priority
?
122 Views
Last Modified: 2014-10-23
Techies--
This stored procedure appears to be writing data correctly for some of the columns, but not for all of the columns. The attached file will generate the table.

USE [SuccessFactors]
GO
/****** Object:  StoredProcedure [staging].[LoadPositions]    Script Date: 10/23/2014 7:37:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		plditallo
-- Create date: 10/22/2014
-- Description:	Populates all Position data from OData version of SuccessFactors
--               to staging.Position
-- =============================================
ALTER PROCEDURE [staging].[LoadPositions]
-- Debug; when working, uncomment 
-- ( @xmlpositions xml
-- )
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

-- Debug; when working comment or remove next 2 lines
declare @xmlpositions xml
set @xmlpositions = '<Positions><Position><effectiveStartDate>2014-06-11T00:00:00</effectiveStartDate><code>25TEST</code><positionControlled></positionControlled><transactionSequence>1</transactionSequence><mdfSystemObjectType>Position</mdfSystemObjectType><location>L001</location><effectiveStatus>A</effectiveStatus><effectiveEndDate>9999-12-31T00:00:00</effectiveEndDate><vacant>false</vacant><description></description><technicalParameters>true;2014-06-11;false;true</technicalParameters><payGrade>ZHE1</payGrade><externalName_en_US>Comp Analyst</externalName_en_US><createdDate>2014-06-19T16:36:13</createdDate><mdfSystemRecordStatus>N</mdfSystemRecordStatus><multipleIncumbentsAllowed>true</multipleIncumbentsAllowed><businessUnit></businessUnit><createdBy>tpadmin</createdBy><company>T123</company><lastModifiedBy>tpadmin</lastModifiedBy><jobCode></jobCode><comment></comment><mdfSystemVersionId></mdfSystemVersionId><department>T200</department><criticality></criticality><division></division><cust_locationgroup></cust_locationgroup><lastModifiedDateWithTZ>2014-06-19T20:36:13Z</lastModifiedDateWithTZ><standardHours></standardHours><jobTitle>Hayleys Test Job</jobTitle><legacyPositionId></legacyPositionId><costCenter>11111</costCenter><targetFTE>1</targetFTE><cust_Workingdaysperweek></cust_Workingdaysperweek><positionTitle></positionTitle><lastModifiedDate>2014-06-19T16:36:13</lastModifiedDate><cust_loctype>LT1</cust_loctype></Position><Position><effectiveStartDate>2014-09-01T00:00:00</effectiveStartDate><code>VPR10001</code><positionControlled></positionControlled><transactionSequence>1</transactionSequence><mdfSystemObjectType>Position</mdfSystemObjectType><location>OK02</location><effectiveStatus>A</effectiveStatus><effectiveEndDate>9999-12-31T00:00:00</effectiveEndDate><vacant>false</vacant><description>Vice Pres of Tire Care and Fac Main</description><technicalParameters></technicalParameters><payGrade>PayGrade3</payGrade><externalName_en_US>Vice Pres of Tire Care and Fac Main</externalName_en_US><createdDate>2014-10-06T13:34:12</createdDate><mdfSystemRecordStatus>N</mdfSystemRecordStatus><multipleIncumbentsAllowed>true</multipleIncumbentsAllowed><businessUnit>Executive</businessUnit><createdBy>ImportAdmin</createdBy><company>1002</company><lastModifiedBy>ImportAdmin</lastModifiedBy><jobCode>VPR1</jobCode><comment></comment><mdfSystemVersionId></mdfSystemVersionId><department>800E</department><criticality></criticality><division>Executive</division><cust_locationgroup>OK</cust_locationgroup><lastModifiedDateWithTZ>2014-10-06T17:34:12Z</lastModifiedDateWithTZ><standardHours></standardHours><jobTitle>Vice President</jobTitle><legacyPositionId></legacyPositionId><costCenter>1002910100</costCenter><targetFTE>100</targetFTE><cust_Workingdaysperweek>5</cust_Workingdaysperweek><positionTitle></positionTitle><lastModifiedDate>2014-10-06T13:34:12</lastModifiedDate><cust_loctype>OFFI</cust_loctype></Position></Positions>'

    INSERT INTO staging.Position 
	(   [EffecitveStartDate],
		[Code],
		[PositionControlled],
		[TransactionSequence],
		[MDFSystemObjectType],
		[Location],
		[EffectiveStatus],
		[EffectiveEndDate],
		[Vacant],
		[Description],
		[TechnicalParameters],
		[PayGrade],
		[ExternalName_en_US],
		[CreatedDate],
		[MDFSystemRecordStatus],
		[MultipleIncumbentsAllowed],
		[BusinessUnit],
		[CreatedBy],
		[Company],
		[LastModifiedBy],
		[JobCode],
		[Comment],
		[MDFSystemVersionId],
		[Department],
		[Criticality],
		[Division],
		[cust_locationgroup],
		[LastModifiedDateWithTZ],
		[StandardHours],
		[JobTitle],
		[LegacyPositionId],
		[CostCenter],
		[TargetFTE],
		[cust_Workingdaysperweek],
		[PositionTitle],
		[LastModifiedDate],
		[cust_loctype]
	)
	SELECT
	     T.c.value('EffecitveStartDate[1]', 'varchar(30)')
		,T.c.value('Code[1]','varchar(20)')
		,T.c.value('PositionControlled[1]', 'varchar(10)')
		,T.c.value('TransactionSequence[1]','varchar(10)')
		,T.c.value('MDFSystemObjectType[1]','varchar(40)')
		,T.c.value('Location[1]','varchar(20)')
		,T.c.value('EffectiveStatus[1]','varchar(10)')
		,T.c.value('EffectiveEndDate[1]','varchar(30)')
		,T.c.value('Vacant[1]','varchar(10)')
		,T.c.value('Description[1]','varchar(200)')
		,T.c.value('TechnicalParameters[1]','varchar(200)')
		,T.c.value('PayGrade[1]','varchar(20)')
		,T.c.value('ExternalName_en_US[1]', 'varchar(100)')
		,T.c.value('CreatedDate[1]','varchar(30)')
		,T.c.value('MDFSystemRecordStatus[1]','varchar(40)')
		,T.c.value('MultipleIncumbentsAllowed[1]','varchar(10)')
		,T.c.value('BusinessUnit[1]','varchar(10)')
		,T.c.value('CreatedBy[1]','varchar(20)')
		,T.c.value('Company[1]','varchar(20)')
		,T.c.value('LastModifiedBy[1]','varchar(20)')
		,T.c.value('JobCode[1]','varchar(20)')
		,T.c.value('Comment[1]','varchar(500)')
		,T.c.value('MDFSystemVersionId[1]','varchar(40)')
		,T.c.value('Department[1]','varchar(40)')
		,T.c.value('Criticality[1]','varchar(20)')
		,T.c.value('Division[1]','varchar(30)')
		,T.c.value('cust_locationgroup[1]', 'varchar(100)')
		,T.c.value('LastModifiedDateWithTZ[1]','varchar(40)')
		,T.c.value('StandardHours[1]', 'varchar(20)')
		,T.c.value('JobTitle[1]','varchar(100)')
		,T.c.value('LegacyPositionId[1]','varchar(100)')
		,T.c.value('CostCenter[1]','varchar(50)')
		,T.c.value('TargetFTE[1]','varchar(30)')
		,T.c.value('cust_Workingdaysperweek[1]','varchar(40)')
		,T.c.value('PositionTitle[1]','varchar(100)')
		,T.c.value('LastModifiedDate[1]','varchar(30)')
		,T.c.value('cust_loctype[1]','varchar(50)')
	 FROM @xmlpositions.nodes('/Positions/Position') as T(c)


END

Open in new window

generatePositionTBL.sql
0
Comment
Question by:ditallop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 2000 total points
ID: 40399342
Cause XML is case-sensitive. Thus any XPath or XQuery expression must use the same case as in the element and attribute names.
0
 

Author Closing Comment

by:ditallop
ID: 40400136
ste5an,
Thanks so much! :)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question