Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in do case command 1

Status
Not open for further replies.

Bondjames

Technical User
Mar 25, 2021
24
IN
sirs
i have dbf with
nqtyp nqtys nqtyn nqtyd nqtyfuel month ndcms ndchsd
321000 5000 4000 302000 632000 4 125291.1 84931.46
279000 15000 4000 258000 556000 5 113141.66 72557.34
289000 10000 10000 263000 572000 6 117318.03 73963.49

the nqtyfuel is total of nqtyp+nqtys+nqtyd+nqtyn for respective months
i have written
DO case
CASE nqtyfuel<400000.000
replace ALL ndcms WITH (nqtyp+nqtys+nqtyn)/1000*379.67 , ndchsd WITH nqtyd/1000*281.23
CASE nqtyfuel<600000.000
replace ALL ndcms WITH (nqtyp+nqtys+nqtyn)/1000*340.19,ndchsd WITH nqtyd/1000*251.99
CASE nqtyfuel<800000.000
replace ALL ndcms WITH (nqtyp+nqtys+nqtyn)/1000*300.72,ndchsd WITH nqtyd/1000*222.75
otherwise
replace ALL ndcms WITH (nqtyp+nqtys+nqtyn)/1000*261.24,ndchsd WITH nqtyd/1000*193.51
ENDCASE

sirs can you please tell me what is wrong in this do case command
because according to calculations for month 4 as
nqtyfuel is >600000 ndcms should be 321000+5000+4000=(330000/1000)*300.72=99237.60 and ndchsd as (302000/1000)*222.75=67270.5
for month5 as nqtyfuel=556000 it should be as
ndcms =279000+15000+4000=(298000/1000)*340.19 =101376.62 and ndchsd as (258000/1000)*251.99=65013.42 and so on

what is error in my do case please as i am getting the figures as shown above
i want to put values accordingly in ndcms and ndchsd
forgive for writting replace all
thanks
regards
 
I doubt that you want this command.
This code just check the result from the current record of the table and acts according to this result for ALL records no matter what is the values of the fields in other records;
Maybe this?
Code:
replace ALL ndcms WITH (nqtyp+nqtys+nqtyn)/1000 * ICASE(nqtyfuel<400000.000, 379.67,;
                                                        nqtyfuel<600000.000, 340.19,;
                                                        nqtyfuel<800000.000, 300.72,;
                                                                             261.24),;
            ndchsd WITH nqtyd/1000              * ICASE(nqtyfuel<400000.000, 281.23,;
                                                        nqtyfuel<600000.000, 251.99,;
                                                        nqtyfuel<800000.000, 222.75,;
                                                                             193.51)

Borislav Borissov
VFP9 SP2, SQL Server
 
i want to put values accordingly in ndcms and ndchsd
forgive for writting replace all
 
Well, either you do as Borislav Borissov suggests instead of all our code. Or you do the replacements one by one record and put your code into a scan loop. But your REPLACE ALL made changes to all records based on only one records nqtyfuel value. Of course that fails the purpose.

If you started your code change with a single REPLACE, that used the same formula for any nqtyfuel and wanted to differentiate that now, then the logical step would have been to do 4 REPLACE ALL statements with FOR clauses for the 4 ranges of nqtyfuel FOR BETWEEN(nqtyfuel,400000.000, FOR BETWEEN(nqtyfuel,400000.000,600000.000) and so on. Or you have to go for single record by record modifications.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top