?
Solved

ADD PCS INTO DOZENS

Posted on 2011-04-26
2
Medium Priority
?
278 Views
Last Modified: 2012-05-11
Hi All,

I have data dozens and pcs.

I want to add those pcs >=12 into dozens, and remain pcs < 12.

Below is my code, but failed to achieve it.
 
 SUM(QtyLsn) +  FLOOR(CAST(SUM(QtyPcs)/12 AS MONEY)) AS QtyLsn
 , SUM(QtyPcs)  - FLOOR(CAST(SUM(QtyPcs)/12 AS MONEY)) AS QtyPcs

How could I do it ?

Thank you.
0
Comment
Question by:emi_sastra
2 Comments
 
LVL 3

Accepted Solution

by:
WyTyz earned 2000 total points
ID: 35465868
Is the modulo-operator what you need? check out the code.
 
DECLARE @pcs INT;
SET @pcs = 27;
SELECT	@pcs / 12 AS dozens,
	@pcs % 12 AS remaining_pcs;

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35466036
Yes, it works.

I use :

 SUM(QtyLsn) +  CAST(SUM(QtyPcs)/12 AS INT) AS QtyLsn
 , SUM(QtyPcs) % 12 AS QtyPcs

Thank you very much for your hep.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

840 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