Author |
Topic |
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-16 : 02:08:28
|
hican u pls let me know how do query and go about to do thisi need to pay the bill say 635 rupees indian currency in the cash counter for eg:keb bill i have/pay 1000 i should get 365 backin the cash countersay dinomination is 1000,500,100,50,20,10,5,2,1 rupeei should get the best possiblitescase 1:100 three and 50+20+10+5 = 365 total notes(7 notes) this is correct(because less currency notes)50+50+50+50+50+50+50+20+10+5(10 notes) this is wrong (because more currency notes)case 2:if 100 is not there 50+50+50+50+50+50+50+20+10+5(10 notes)(this is correct)database |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-16 : 02:23:30
|
[code]CREATE FUNCTION dbo.fnCashReturn( @Prize INT, @Paid INT)RETURNS @Out TABLE (BillSize INT)ASBEGIN DECLARE @CashCounter TABLE (BillSize INT, Items INT) -- This code below should come from your real cash counter table INSERT @CashCounter SELECT 1000, 1 UNION ALL SELECT 500, 10 UNION ALL SELECT 100, 1 UNION ALL SELECT 50, 2 UNION ALL SELECT 20, 10 UNION ALL SELECT 10, 40 UNION ALL SELECT 5, 250 UNION ALL SELECT 2, 7 UNION ALL SELECT 1, 9 -- This code above should come from your real cash counter table DECLARE @Return INT, @BillSize INT SELECT @Return = @Paid - @Prize WHILE @Return > 0 BEGIN SELECT @BillSize = MAX(BillSize) FROM @CashCounter WHERE BillSize <= @Return AND Items > 0 INSERT @Out SELECT @BillSize SELECT @Return = @Return - @BillSize UPDATE @CashCounter SET Items = Items - 1 WHERE BillSize = @BillSize END RETURNEND[/code]Call with either [code]select *from dbo.fnCashReturn(635, 1000)order by BillSize desc[/code]or[code]select COUNT(*) Items, BillSizefrom dbo.fnCashReturn(635, 1000)GROUP BY BillSizeorder by BillSize desc[/code]Peter LarssonHelsingborg, Sweden |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-16 : 02:45:59
|
This all sounds very good. Just wondering how accurate it will be for the notes in the cash drawer against the POS. KH |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-16 : 03:37:46
|
Can be, it the code is turned into a SP and work directly against POS.Some Foreign Currency Exchange Offices still works this way. I wrote an app in Pascal in spring 1990, and that office still uses my app.Peter LarssonHelsingborg, Sweden |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-16 : 03:48:39
|
Well you can't help if the cashier decided to give 2 50 notes instead of a 100 note  KH |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-16 : 03:51:29
|
Certainly not. But that's an front end decision, right? Peter LarssonHelsingborg, Sweden |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-16 : 04:05:23
|
LOL ! Yes. You are absolutely correct  KH |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-17 : 05:58:40
|
hiif x person goes for shopping when he/she pays bill at cash counter his bill amount is 986.But the customer x has 1000 rupees in his hand and he pays the bill he should get back/balance amount 14 rupees back rightin this scenario the cash counter should give x person the least or less number of notes best probabilitieseg: in cash counter he has currency demoniation 1000,500,100,50,20,10,9,7,5,2,1 etc rupee currency noteswhere 10+2+2=14 or 2+2+2+2+2+2+2=14 logically this correct but actually cash counter should give customer 7+7=14 because this is the least/less currency demoniation notes(count)i should have a query which will fetch least/less number(count) of currency notes note: cash counter should give minimum number of currency notesi think we should use function/dynamic query array algorithm in my database i have different demoniation for 14 rupees best possibilities is 7+7=14 not 10+2+2=14 or 2+2+2+2+2+2+2=14i ran ur function it retuns me 1 1002 508 201 5thanxsdatabase |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-18 : 14:00:47
|
http://www.sqlteam.com/forums/topic.asp?whichpage=2&TOPIC_ID=73610#264068Peter LarssonHelsingborg, Sweden |
 |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2006-10-18 : 14:35:23
|
quote: Are you insane?
Rhetorical question i assume [Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|