Posted on 2011-04-26
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.
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;

    Open in new window

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    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 ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( 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…

    761 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

    15 Experts available now in Live!

    Get 1:1 Help Now