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 6005237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:16+00:00 2026-05-23T01:22:16+00:00

I have a SQL Server 2008 table with 50k rows, each with an XML

  • 0

I have a SQL Server 2008 table with 50k rows, each with an XML fragment in a varchar column that looks like this:

<infoElems>
        <infoElem id="1" Name="somename" money="3399.3984939" />
</infoElems>

I need to select out the varchar column, select out the money attribute, change it to an actual money type (3399.40 in my example), and then put the whole fragment back.

Can anyone point how to get me through this? I think I need to create an XML index of some sort? Confused.

Thanks.

  • 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-23T01:22:17+00:00Added an answer on May 23, 2026 at 1:22 am

    The datatypes involved make this ugly, especially if the XML in your columns varies other than the price. Here is something that will work in SQL 2008. If you have to update lots of rows you will have to use this with a CURSOR.

    DECLARE @orig VARCHAR(20), @new money
    DECLARE @origXml XML, @newXml VARCHAR(100)
    
    // first you have to cast to xml
    SELECT @origXml = CAST(myColunm AS XML) 
    FROM dbo.Tbl1
    WHERE ...
    
    // then extract the value as a string
    SET @orig = @origXml.value('(//infoElem/@money)[1]','varchar(20)') 
    
    // then get the new value to the right percision - MONEY is accurate to the ten-thousandth hence the ROUND
    SET @new = ROUND(CAST(@orig AS MONEY),2)  
    
    SET @newXml = REPLACE(CAST(@origXml AS VARCHAR(100)),  
      'money="'+CAST(@orig AS VARCHAR)+'"',
      'money="'+CAST(@new AS VARCHAR)+'"') // then replace - this can be combined with the update 
    
    UPDATE dbo.Tbl1 SET myColunm = @newXml // then update
    

    Depending on your situation, it may be easier to just write an external script to do this. You could also look into using regex – see this post, but that could get really ugly.

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

Sidebar

Related Questions

I have a SQL Server 2008 table with a column of the geography datatype.
I have SQL Server 2008 with a table called ProductCategories designed like this: Id
I have a SQL Server 2008 database table that uses uniqueidentifier as a primary
I have a Money column in my SQL Server 2008 table. In my below
I have a table with a time column in my SQL Server 2008 database.
I have a table that contains a GEOMETRY data type. SQL Server 2008 ships
I have a field in my SQL Server 2008 table that is auto number
I have a SQL Server 2008 R2 table with nvarchar(4000) field. Data that stores
i have a table with jobs like this in a MS SQL Server 2008
I have a table with 300 million rows in Microsoft SQL Server 2008 R2.

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.