Solved

SQL - Multiplication Query and updating to the Column

Posted on 2011-09-07
2
469 Views
Last Modified: 2012-05-12
SQL 2008 :-

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].


Ship Qty    Size             Qty
1           100 EA           100
3           60 EA            180
2           60X3ML           360
update [TableName] set Qty = [Ship Qty] * CONVERT(INT, (Size)) * CONVERT(Float, (Size))                 WHERE  Size > 0                     AND Size > 0                     AND Qty IS NULL

Open in new window

0
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
DavidMorrison earned 500 total points
ID: 36496908
Try

update TN
set TN.Qty =
      (case TN.size
            when '100 EA' then 100
            when '60 EA' then 60
            when '3 ML' then 3
            when '60x3ML' then 180
      end) * TN.[Ship Qty]
from TableName as TN
0
 

Author Closing Comment

by:chokka
ID: 36496937
Thanks
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question