Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:30:35+00:00 2026-06-12T23:30:35+00:00

OpenXML: DECLARE @idoc int DECLARE @doc varchar(1000) SET @doc = ‘<ROOT> <Employee EmployeeID =

  • 0

OpenXML:

DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc =
'<ROOT>
        <Employee EmployeeID = "1"  EmpStatus = "Full Time"/>
        <Employee EmployeeID = "2"  EmpStatus ="Part Time" />
        </ROOT>'
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT    *
FROM       OPENXML (@idoc, '/ROOT/Employee',1)
            WITH (EmployeeID  varchar(10),
                  EmpStatus varchar(20))

Results:

EmployeeID    EmpStatus
    1         Full Time
    2         Part Time

Table query:

    SELECT hr.EmployeeID, hr.Title, c.FirstName,c.LastName 
    FROM HumanResources.Employee hr WITH (NOLOCK)
    INNER JOIN ContactInfo c WITH (NOLOCK)
    ON hr.ContactID = c.ContactID
    Where hr. EmployeeID IN ( 1, 2)

Results:

EmployeeID  Title         FirstName  LastName
    1   Engineering   Mike       Brown
    2   Programmer    Yves       Anthony

How to join OpenXML data to my inner join query using EmployeeID?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:30:36+00:00Added an answer on June 12, 2026 at 11:30 pm

    Do you insist on using OpenXML? It’s old, it’s legacy – using the native XQuery functions typically is much easier.

    Try something like this:

    DECLARE @Employees TABLE (EmployeeID INT, Title VARCHAR(20), FirstName VARCHAR(20),LastName VARCHAR(20))
    
    INSERT INTO @Employees VALUES(1, 'Engineering', 'Mike', 'Brown')
    INSERT INTO @Employees VALUES(2, 'Programmer', 'Yves', 'Anthony')
    
    DECLARE @doc XML 
    SET @doc = '<ROOT>
                  <Employee EmployeeID = "1"  EmpStatus = "Full Time"/>
                  <Employee EmployeeID = "2"  EmpStatus ="Part Time" />
                </ROOT>'
    
    ;WITH XmlCTE AS
    (
        SELECT
            EmpID = Empl.value('@EmployeeID', 'int'),
            EmpStatus = Empl.value('@EmpStatus', 'varchar(10)')
        FROM @doc.nodes('/ROOT/Employee') AS Tbl(Empl)
    )
    SELECT 
        e.*, x.EmpStatus 
    FROM 
        @Employees e
    INNER JOIN  
        xmlcte x ON e.EmployeeID = x.EmpID
    

    This gives me an output of:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ALTER PROCEDURE GetSingersGenere (@SingerData ntext) AS BEGIN DECLARE @hDoc int exec sp_xml_preparedocument @hDoc OUTPUT,@SingerData
I have this xml : DECLARE @x XML SET @x = '<data> <add>a</add> <add>b</add>
DECLARE @str NVARCHAR(MAX) SET @str = '<bands > <title>my bands</title> <band> <fullName>beatles</fullName> <members> <member
I'm using OpenXML SDK with Word to produce labels. The base Word doc has
Suppose I have a query like this - SELECT * FROM OPENXML(@i, '/root/authors', 2)
I need to pass set of int to sql procedure. alter PROC PrCustomerServicesUpd( @CustomerId
Hi i have an xml string DECLARE @XmlQue NTEXT SET @XmlQue='<?xml version=1.0 encoding=UTF-16?><Template TId=1>
I am using openXML and C# to generate a powerpoint slide but I can't
I use OpenXML SDK 2.0 to generate Excel file with large amount of data,
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.