SQL Server - Select attribute from XML Field

Posted on 2012-08-21
Last Modified: 2012-08-21
I have an field as an XML datatype.  I want to parse out a particular attribute.

See the start of the XML data.  How do I parse out, via SQL, just the "requestMachineName" data?

<UnitCheckInRequest xmlns:xsi="" requestUserIdentity="sample"
Question by:EricLynnWright
    LVL 3

    Accepted Solution

    select UnitCheckInXmlMessage.value('(/UnitCheckInRequest/@requestMachineName)[1]','varchar(20)') as Machine Name
      from UnitCheckInTransaction
    LVL 4

    Expert Comment

    SELECT  ColumnName.value('(/UnitCheckInRequest/@requestMachineName)[1]', 'varchar')
    FROM TableName
    LVL 3

    Author Comment

    Sorry.  With the help you gave me from the other question, I was able to find it.

    Thanks again for all the help!  I greatly appreciate it.
    LVL 3

    Author Comment


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
    Viewers will learn how the fundamental information of how to create a table.

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now