Solved

xquery working only for some columns/elements

Posted on 2014-10-23
2
104 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
2 Comments
 
LVL 32

Accepted Solution

by:
Stefan Hoffmann earned 500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server Log File Space 6 33
sql query 7 34
combine an MS SQL string in Idera DM 9 28
backups - Strategies 1 12
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now