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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:49:06+00:00 2026-05-24T05:49:06+00:00

I am not very familiar with using XML in SQL Server and I have

  • 0

I am not very familiar with using XML in SQL Server and I have been asked to update this stored procedure and modify it to apply some math to a field before inserting it into the table.

Here is some example code:

CREATE PROCEDURE [spNewUser]
    @UserInfo xml
AS    
BEGIN
    IF @UserInfo.exist('/UserInfo') = 1
    BEGIN
        DECLARE 
            @FirstName varchar(40),
            @LastName varchar(40),
            @Height varchar(10)
        SELECT
            @FirstName = Personal.query('FirstName').value('.','varchar(25)'),
            @LastName = Personal.query('LastName').value('.','varchar(50)'),
            @Height = NULLIF(Personal.query('HeightFt').value('.','varchar(3)') + '.' + Personal.query('HeightIn').value('.','varchar(3)'),'.')
        FROM
            @UserInfo.nodes('/UserInfo/Personal') AppInfo(Personal)
    END
BEGIN

Now I understand (in general) everything happening. We used to store height (in feet and inches) as 'FootValue'.'InchValue' because we didn’t use it for anything, but now we want to use it for something. We are going to store it as an int now, and save the number of inches. I want to do HeightFt * 12 + HeightIn but I am unsure the safest way to convert and do the math. I am not sure how to do the query('HeightFt').value(???) statement. I would want it to return 0 if not existent.

  • 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-24T05:49:07+00:00Added an answer on May 24, 2026 at 5:49 am

    I would recommend to store numeric values as numerics – not varchar(10). Basically, you should extract those values from the XML and then do your calculation afterwards:

    DECLARE 
       @FirstName varchar(40),
       @LastName varchar(40),
       @HeightFt decimal(16, 4),
       @HeightIn decimal(16, 4)
    
    SELECT
        @FirstName = Personal.value('(FirstName)[1]', 'varchar(25)'),
        @LastName = Personal.value('(LastName)[1]', 'varchar(50)'),
        @HeightFt = ISNULL(Personal.value('(HeightFt)[1]', 'DECIMAL(6, 1)'), 0.0),
        @HeightIn = ISNULL(Personal.value('(HeightIn)[1]', 'DECIMAL(6, 1)'), 0.0)
    FROM
      @UserInfo.nodes('/UserInfo/Personal') AppInfo(Personal)
    
    DECLARE @Calculated DECIMAL(8, 2)
    
    SET @Calculated = @HeightFt * 12 + @HeightIn
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not very familiar with databases and the theories behind how they work.
Not very technical, but... I have to implement a bad words filter in a
( Updated a little ) I'm not very experienced with internationalization using PHP, it
Currently in our enterprise we have a situation that i think it's not very
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
We have had issues with Mootools not being very backward compatible specifically in the
I'm not very familiar with xpath. But I was working with xpath expressions and
I'm not too familiar with c++ and how instantiating objects work, so this is
I am not very good with Regex but I am learning. I would like
I'm not very good at C, and I always get stuck on simple string

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.