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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:21:41+00:00 2026-05-23T11:21:41+00:00

SQL Server 2008 : I have a table with three columns Ship Qty, Size,

  • 0

SQL Server 2008 : I have a table with three columns Ship Qty, Size, Qty.

We need to update the column Qty by multiplying two other columns.

At present this is the data in the table

Ship Qty            Size              Qty
2                   1*100  EA         NULL
3                   3*20 ML           

Expected result after query

Ship Qty            Size              Qty
2                   1*100  EA         200
3                   3*20 ML           180
  1. Split Size to Size1 (Before X) and Size2 (Behind X) (e.g 1X100 EA => Size1 = 1, SIze2=100)
  2. Multiply Ship Qty * Size1 * Size2
  3. Update Field qty with the result where qty is null or empty

I have no idea, how can I do it inside SQL Server? I am sure a stored procedure would be helpful !

  • 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-23T11:21:42+00:00Added an answer on May 23, 2026 at 11:21 am

    Here is one try. It makes a lot of assumptions, e.g. that no space will occur until AFTER Size2 and that both sides of the * (or X from your description – which is it?) will be convertible to INT.

        DECLARE @foo TABLE
        (
            [Ship Qty] INT,
            Size VARCHAR(32),
            Qty INT
        );
    
        INSERT @foo([Ship Qty], Size)
        SELECT 2, '1*100 EA'
        UNION SELECT 3, '3*20 ML';
    
        UPDATE @foo SET
            Qty = [Ship Qty] * CONVERT(INT, LEFT(Size, CHARINDEX('*', Size)-1)) * 
            CONVERT(INT, SUBSTRING(Size, CHARINDEX('*', Size)+1, 
                CHARINDEX(' ', Size)-CHARINDEX('*', Size)))
        WHERE
            CHARINDEX('*', Size) > 0
            AND CHARINDEX(' ', Size) > 0
            AND Qty IS NULL;
    
        SELECT [Ship Qty], Size, Qty FROM @foo;
    

    I strongly recommend storing this data better. Instead of storing “1*100 EA” store 1 in a column, 100 in a column, and EA in a column. This is going to be a nightmare to maintain, never mind to enforce that the size column gets consistent data (and that your formula will work against all future implementations).

    I also suggest not having column names with special characters (e.g. spaces). Nobody likes having to type square brackets when they can be avoided.

    Finally, if you can enforce the data on input, you should consider a computed column or view. You shouldn’t have to constantly go back and update the table after the fact.

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

Sidebar

Related Questions

I'm using SQL Server 2008 and I have a table with three columns: Length
I have a SQL Server 2008 database table with three varchar Columns - Col1,
I am talking about SQL Server 2008. I have table with three nvarchar columns.
I use SQL Server 2008 and have a table with 5 char typed columns.
Playing around with SQL Server 2008 and I have a table People with columns:
I have a table in SQL Server 2005 which has three columns: id (int),
I'm using SQL Server 2008; Suppose I have a table 'X' with columns 'Date1',
I have got a table in SQL Server 2008 where I need alternating values
I have a Microsoft SQL Server 2008 query that returns data from three tables
In SQL Server 2008: I have one table, and I want to do something

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.