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

  • SEARCH
  • Home
  • 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 3793388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:46:05+00:00 2026-05-19T12:46:05+00:00

I have a row of excel data (i.e. several cells from an excel sheet)

  • 0

I have a row of excel data (i.e. several cells from an excel sheet) saved into a SQL Server table, in a column that is of datatype XML.

I need to update the value, in a particular cell, in this data saved in the XML column, with a new value that is stored in another column in the same table.
How do I do that?

I am not able to even select the cell propery using the XMLColumnName.Query() method in T-SQL of SQL Server 2005.

Pasting a sample table, with sample rows here, so you can experiment and let me know if you were able to figure this out! Thank you!!

-Shiva

    -- reference article for XML data manipulation 
-- http://msdn.microsoft.com/en-us/library/ms345117(v=sql.90).aspx#sql2k5xml_topic3

  -- create test table for xml data 
CREATE TABLE testdocs (pk INT PRIMARY KEY, xCol XML not null)

  -- insert 1 row of test data
insert into testdocs values(1,'<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
  xmlns:o="urn:schemas-microsoft-com:office:office" 
  xmlns:x="urn:schemas-microsoft-com:office:excel" 
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
  xmlns:html="http://www.w3.org/TR/REC-html40">
  <Worksheet ss:Name="TestSheet">
    <Table ss:ExpandedColumnCount="509" ss:ExpandedRowCount="1" ss:StyleID="s191">
      <Column ss:StyleID="s1" ss:AutoFitWidth="0" ss:Width="55" />
      <Column ss:StyleID="s2" ss:AutoFitWidth="0" ss:Width="55" />
      <Row>
        <Cell>
          <Data ss:Type="String">TestValue1</Data>
        </Cell>        
        <Cell>
          <Data ss:Type="String">TestValue2</Data>
        </Cell>
      </Row>
    </Table>
  </Worksheet>
</Workbook>')

  -- select records, and inspect the XML in SSMS
select * from testdocs

-- want to replace / update "TestValue2" in the XML for the 1s rows, to "New TestValue2"
-- location in XML hierarchy is as follows

    /Workbook/Worksheet/Table/Row/Cell/Data

-- how do i do that ?
  • 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-05-19T12:46:06+00:00Added an answer on May 19, 2026 at 12:46 pm

    You need to get the XML namespaces properly:

    with xmlnamespaces (
        DEFAULT 'urn:schemas-microsoft-com:office:spreadsheet'
        , 'urn:schemas-microsoft-com:office:office' as o
        , 'urn:schemas-microsoft-com:office:excel' as x
        , 'urn:schemas-microsoft-com:office:spreadsheet' as ss
        , 'http://www.w3.org/TR/REC-html40' as html)
    select xCol.value ('(/Workbook/Worksheet/Table/Row/Cell/Data)[1]','varchar(100)') as Data
    from testdocs
    

    Update:

    with xmlnamespaces (
        DEFAULT 'urn:schemas-microsoft-com:office:spreadsheet'
        , 'urn:schemas-microsoft-com:office:office' as o
        , 'urn:schemas-microsoft-com:office:excel' as x
        , 'urn:schemas-microsoft-com:office:spreadsheet' as ss
        , 'http://www.w3.org/TR/REC-html40' as html)
    update testdocs
    set xCol.modify (' replace value of (/Workbook/Worksheet/Table/Row/Cell/Data/text())[1]
        with "ReplacedValue1"');
    
    select  * from testdocs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.