Solved

Posted on 2011-04-26
258 Views
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
Question by:emi_sastra

LVL 3

Accepted Solution

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;
``````
0

LVL 1

Author Comment

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

### Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…