Solved

SQL - Multiplication Query and updating to the Column

Posted on 2011-09-07
2
465 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

821 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