Solved

SQL - Multiplication Query and updating to the Column

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

746 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

10 Experts available now in Live!

Get 1:1 Help Now