473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

denomination breakdown

Is it possible to use SQL to take a field, and break it down by
denominations?

I would like to take a field, and then break this out into the number
of bills($100's, $50's, etc) I would need:
$469.32 =
4x$100
1x$50
1x$10
1x$5
4x$1
etc.

May 15 '07 #1
3 4564
SELECT [tblCash].[Amount], [tblCash].[Amount]\100 AS N100, [N100] & "x$100"
AS Expr1, ([tblCash].[Amount]-[N100]*100)\50 AS N50, [n50] & "x$50" AS
Expr2, ([tblCash].[Amount]-[N100]*100-[N50]*50)\10 AS N10, [n10] & "x$10" AS
Expr3, ([tblCash].[Amount]-[N100]*100-[N50]*50-[n10]*10)\5 AS n5, [n5] &
"x$5" AS Expr4, ([tblCash].[Amount]-[N100]*100-[N50]*50-[n10]*10-[n5]*5)\1
AS n1, [n1] & "x$1" AS Expr5,
CInt(([tblCash].[Amount]-[N100]*100-[N50]*50-[n10]*10-[n5]*5-[n1])*100) AS C
FROM [tblCash];

"Daron" <Da**********@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Is it possible to use SQL to take a field, and break it down by
denominations?

I would like to take a field, and then break this out into the number
of bills($100's, $50's, etc) I would need:
$469.32 =
4x$100
1x$50
1x$10
1x$5
4x$1
etc.

May 15 '07 #2
On May 15, 2:44 pm, Daron <Daron.Low...@gmail.comwrote:
Is it possible to use SQL to take a field, and break it down by
denominations?

I would like to take a field, and then break this out into the number
of bills($100's, $50's, etc) I would need:
$469.32 =
4x$100
1x$50
1x$10
1x$5
4x$1
etc.
This is an interesting problem. To solve the problem in complete
generality is difficult because all the Denomination values need to be
known in order to be confident that the correct remaining amount is
calculated. I believe that for the example you give (100, 50, 10, 5,
1, ...) that this is not the case and that it is sufficient to know
only the previous Denomination in order to produce the
breakdowns :-). Also, I didn't test the limits beyond the example I
give.

tblDenomination
DID AutoNumber
Denomination Double
DenominationName Text
DID Denomination DenominationName
1 100 C-note
2 50 Fiddy
3 10 Sawbuck
4 5 Five
5 1 Buck
6 0.5 Half Dollar
7 0.1 Dime
8 0.05 Nickel
9 0.01 Penny

tblI
ID AutoNumber
I Long
ID I
1 1
2 2
....
18 18

tblBreakdown
BID AutoNumber
BreakdownAmount Currency
BID BreakdownAmount
1 $1,234,469.32

qryMakeChange:
SELECT (SELECT A.Denomination FROM tblDenomination AS A WHERE A.DID =
tblI.I) AS Denomination, Nz((SELECT A.Denomination FROM
tblDenomination AS A WHERE A.DID = tblI.I - 1), 0) AS
PrevDenomination, Int(tblBreakdown.BreakdownAmount / (SELECT
A.Denomination FROM tblDenomination AS A WHERE A.DID = tblI.I - 1))
AS X, Int(tblBreakdown.BreakdownAmount / (SELECT A.Denomination FROM
tblDenomination AS A WHERE A.DID = tblI.I)) AS Y, BreakdownAmount - Y
* Denomination As Remainder, BreakdownAmount - Nz(X, 0) *
PrevDenomination As PrevRemainder, (PrevRemainder - Remainder) /
Denomination AS HowMany, (SELECT A.DenominationName FROM
tblDenomination AS A WHERE A.DID = tblI.I) AS DenominationName FROM
tblBreakdown, tblI WHERE tblI.I <= (SELECT Count(*) FROM
tblDenomination) ORDER BY BID, I;

!qryMakeChange:
Denomination PrevDenomination X Y Remainder PrevRemainder HowMany
DenominationName
1000 0 Null 123 $4,469.32 $1,234,469.32 123 10G
5000 10000 123 246 $4,469.32 $4,469.32 0 5G
1000 5000 246 1234 $469.32 $4,469.32 4 Grand
500 1000 1234 2468 $469.32 $469.32 0 Five Hundy
100 500 2468 12344 $69.32 $469.32 4 C-note
50 100 12344 24689 $19.32 $69.32 1 Fiddy
10 50 24689 123446 $9.32 $19.32 1 Sawbuck
5 10 123446 246893 $4,32 $9.32 1 Five
1 5 246893 1234469 $0.32 $4.32 4 Buck
0.5 1 1234469 2468938 $0.32 $0.32 0 Half Dollar
0.1 0.5 2468938 12344693 $0.02 $0.32 3 Dime
0.05 0.1 12344693 24689386 $0.02 $0.02 0 Nickel
0.01 0.05 24689386 123446932 $0.00 $0.02 2 Penny

If tblBreakdown has more than one amount, the query should show each
breakdown consecutively. Note that the breakdown is incorrect if the
DID values aren't consecutive or if, say, quarters are added to the
mix. I may come back to this problem later.

James A. Fortune
CD********@FortuneJames.com

May 20 '07 #3
On May 19, 10:50 pm, CDMAPos...@FortuneJames.com wrote:
On May 15, 2:44 pm, Daron <Daron.Low...@gmail.comwrote:
Is it possible to use SQL to take a field, and break it down by
denominations?
I would like to take a field, and then break this out into the number
of bills($100's, $50's, etc) I would need:
$469.32 =
4x$100
1x$50
1x$10
1x$5
4x$1
etc.

This is an interesting problem. To solve the problem in complete
generality is difficult because all the Denomination values need to be
known in order to be confident that the correct remaining amount is
calculated. I believe that for the example you give (100, 50, 10, 5,
1, ...) that this is not the case and that it is sufficient to know
only the previous Denomination in order to produce the
breakdowns :-). Also, I didn't test the limits beyond the example I
give.

tblDenomination
DID AutoNumber
Denomination Double
DenominationName Text
DID Denomination DenominationName
1 100 C-note
2 50 Fiddy
3 10 Sawbuck
4 5 Five
5 1 Buck
6 0.5 Half Dollar
7 0.1 Dime
8 0.05 Nickel
9 0.01 Penny

tblI
ID AutoNumber
I Long
ID I
1 1
2 2
...
18 18

tblBreakdown
BID AutoNumber
BreakdownAmount Currency
BID BreakdownAmount
1 $1,234,469.32

qryMakeChange:
SELECT (SELECT A.Denomination FROM tblDenomination AS A WHERE A.DID =
tblI.I) AS Denomination, Nz((SELECT A.Denomination FROM
tblDenomination AS A WHERE A.DID = tblI.I - 1), 0) AS
PrevDenomination, Int(tblBreakdown.BreakdownAmount / (SELECT
A.Denomination FROM tblDenomination AS A WHERE A.DID = tblI.I - 1))
AS X, Int(tblBreakdown.BreakdownAmount / (SELECT A.Denomination FROM
tblDenomination AS A WHERE A.DID = tblI.I)) AS Y, BreakdownAmount - Y
* Denomination As Remainder, BreakdownAmount - Nz(X, 0) *
PrevDenomination As PrevRemainder, (PrevRemainder - Remainder) /
Denomination AS HowMany, (SELECT A.DenominationName FROM
tblDenomination AS A WHERE A.DID = tblI.I) AS DenominationName FROM
tblBreakdown, tblI WHERE tblI.I <= (SELECT Count(*) FROM
tblDenomination) ORDER BY BID, I;

!qryMakeChange:
Denomination PrevDenomination X Y Remainder PrevRemainder HowMany
DenominationName
1000 0 Null 123 $4,469.32 $1,234,469.32 123 10G
5000 10000 123 246 $4,469.32 $4,469.32 0 5G
1000 5000 246 1234 $469.32 $4,469.32 4 Grand
500 1000 1234 2468 $469.32 $469.32 0 Five Hundy
100 500 2468 12344 $69.32 $469.32 4 C-note
50 100 12344 24689 $19.32 $69.32 1 Fiddy
10 50 24689 123446 $9.32 $19.32 1 Sawbuck
5 10 123446 246893 $4,32 $9.32 1 Five
1 5 246893 1234469 $0.32 $4.32 4 Buck
0.5 1 1234469 2468938 $0.32 $0.32 0 Half Dollar
0.1 0.5 2468938 12344693 $0.02 $0.32 3 Dime
0.05 0.1 12344693 24689386 $0.02 $0.02 0 Nickel
0.01 0.05 24689386 123446932 $0.00 $0.02 2 Penny

If tblBreakdown has more than one amount, the query should show each
breakdown consecutively. Note that the breakdown is incorrect if the
DID values aren't consecutive or if, say, quarters are added to the
mix. I may come back to this problem later.

James A. Fortune
CDMAPos...@FortuneJames.com
I had four more Denominations when I ran this test. Also, the first
line from !qryMakeChange should have started with 10000.

James A. Fortune
CD********@FortuneJames.com

May 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marek Augustyn | last post by:
Hello, I'm getting strange exception raised using module logging. It's strange because it happens only sometimes, and it happens in different places (but always in a logging method). i.e. this...
10
by: Sean Ross | last post by:
Here's a breakdown of most of the syntax discussed re: PEP318 using an example from python-dev. There are probably several more (I've added ). The example applies both function decoration and...
3
by: Steven Bethard | last post by:
Just wanted to let everyone know that I went through the wiki and tried to consolidate some of the advantages/disadvantages of the various syntax decisions: ...
5
by: Brendan Grant | last post by:
The following describes a problem I have been having for the better part of 3 months, for approximately the last month however I have been focused solely on solving it and seem to be no nearer now...
0
by: BuddyWork | last post by:
Hello, I want to know if there any good tools out there which will show me a breakdown of the memory allocation in Gen 2 heap, basically a breakdown by object is what I'm looking for. The...
16
by: Atley | last post by:
I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to...
3
by: vanidosa27 | last post by:
I need to write a code that calculates the change due after the user has input the amount owed and amount paid. This is easy enough! :rolleyes: My problem comes in when the program wants you to...
1
by: ebrainers | last post by:
Hello Friends! I have three questions I wish to ask with regard to some tasks I am performing in Ms Access 2003. 1. I have a start up form named “Splash” which I want it to load for some...
1
by: Benny | last post by:
I might be overcomplicating the solution, but the problem is I have to make a breakdown of each week for many ranges of dates within a particular year. So for example one record might have a start...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.