ADD PCS INTO DOZENS

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.
LVL 1
emi_sastraAsked:
Who is Participating?
 
WyTyzConnect With a Mentor Commented:
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
 
emi_sastraAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.