Solved

SQL - Multiplication Query and updating to the Column

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now