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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:16:59+00:00 2026-05-25T11:16:59+00:00

SQL 2008 – Simple Query logic. In my Table :TableName, i have 3 columns

  • 0

SQL 2008 – Simple Query logic.

In my Table :TableName, i have 3 columns [Ship Qty], Size, Qty.

Default value for Qty is NULL. I wrote an Update Query to update the column : Qty. I need to multiply [Ship Qty] * Size.

Column : Size is nvarchar. It carries two conditons

1) If the value is 60 EA or 3 ML, I need to consider only 60 or 3 or 3.5 …

2) If the value is 60X3 ML, I need to consider 60X3 which is 180. Then, this multiplied value will be multiplied with [Ship Qty].

update [TableName]
set Qty = [Ship Qty] * CONVERT(INT, (Size)) * CONVERT(Float, (Size))     
           WHERE  Size > 0         
           AND Size > 0         
           AND Qty IS NULL


Ship Qty    Size             Qty
1           100 EA           100
3           60 EA            180
2           60X3ML           360

In the above table, Column : Qty is updated through SQL Query. My Query throws exception.

  • 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-25T11:16:59+00:00Added an answer on May 25, 2026 at 11:16 am

    Bad/odd design but for what hopefully a one-off fix;

    ;with TEST ([Ship Qty], Size) as (
        select 1,'100 EA' union all
        select 3,'60 EA'  union all
        select 2,'60X3ML' union all
        select 2,'60X2ML' union all
        select 2,'60'     union all
        select 2,'1 X3PP'
    )
    select 
        [Ship Qty],
        Size,
        [Ship Qty] * (
                cast(substring(Size, 1, patindex('%[^0-9]%', Size + '/') - 1) as int)
                *
                case when charindex('X', Size, 1) > 0 then
                    cast(substring(substring(Size, charindex('X', Size) + 1, len(Size)), 1, patindex('%[^0-9]%', substring(Size, charindex('X', Size) + 1, len(Size)) + '/') - 1) as int)
                else 
                    1
                end
            )
    from TEST
    

    For

    Ship Qty    Size    (No column name)
    1           100 EA  100
    3           60 EA   180
    2           60X3ML  360
    2           60X2ML  240
    2           60      120
    2           1 X3PP  6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use ms sql 2008 I have problem to add a default value to
I have my Microsoft SQL 2008 Database Entity with one Table containing 6 Columns
I have a SQL 2008 table with a field called RecDate of type DateTimeOffset
I'm using MS SQL 2008 and I have a table of statuses (id, name)
I have a SQL 2008 database table like this name score ----------------------- steve 207
I wrote this very simple SP in SQL 2008: Create procedure dbo.GetNextID ( @TableName
SQL 2008 / 2005 I have SQL Query Syntax issue on Case Statement -
SQL 2008 I have a commission table that looks like this: Comm% | ProfitStartRange
In SQL 2008, I have a query like so: QUERY A UNION QUERY B
In my SQL 2008 database table, I have one column name AUTHOR that contains

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.