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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if-then-else Statement help needed

Status
Not open for further replies.

joybee36

Technical User
Feb 10, 2006
29
US
Trying to figure sales tax when counties have different tax rates....

I'm getting a "boolean expected here" (??), fairly new to if-then-else statements. What have I got wrong here? Writing in Crystal Syntax

if {oelinhst_sql.item_no} in ["REC001", "REC001A"] and
{020708_counties.COUNTYNM_}="Mecklenburg"
then (34.95 * .0725)*{oelinhst_sql.qty_ordered}
else if {020708_counties.COUNTYNM_} <> "Mecklenburg"
then (??)(34.95 * .0675)*{oelinhst_sql.qty_ordered} and
if not ({oelinhst_sql.item_no} in ["REC001A", "REC001"]) and
{020708_counties.COUNTYNM_}="Mecklenburg"
then ({oelinhst_sql.unit_price} * .0725)*{oelinhst_sql.qty_ordered}
else if {020708_counties.COUNTYNM_} <> "Mecklenburg"
then ({oelinhst_sql.unit_price} * .0675)*{oelinhst_sql.qty_ordered}
 
Try:

if {oelinhst_sql.item_no} in ["REC001", "REC001A"] and
{020708_counties.COUNTYNM_}="Mecklenburg"
then (34.95 * .0725)*{oelinhst_sql.qty_ordered}
else
if {020708_counties.COUNTYNM_} <> "Mecklenburg"
then (??)(34.95 * .0675)*{oelinhst_sql.qty_ordered}
<b>else</b>
if not ({oelinhst_sql.item_no} in ["REC001A", "REC001"]) and
{020708_counties.COUNTYNM_}="Mecklenburg"
then ({oelinhst_sql.unit_price} * .0725)*{oelinhst_sql.qty_ordered}
else
if {020708_counties.COUNTYNM_} <> "Mecklenburg"
then ({oelinhst_sql.unit_price} * .0675)*{oelinhst_sql.qty_ordered}


I think there was an 'and' instead of an 'else' operator snuck in there.

Sometimes paranthesis can help maintain your sanity when dealing with nested or multiple if-then-else statements.

Break each section down into chunks to make it clearer what you are aiming for, or opt for a case statement to give the same functionality in a clearer fashion.

'J
 
Ahh, one day I will preview my posts.... Let me repost that *correctly*

if {oelinhst_sql.item_no} in ["REC001", "REC001A"] and
{020708_counties.COUNTYNM_}="Mecklenburg"
then (34.95 * .0725)*{oelinhst_sql.qty_ordered}
else
if {020708_counties.COUNTYNM_} <> "Mecklenburg"
then (??)(34.95 * .0675)*{oelinhst_sql.qty_ordered}
else
if not ({oelinhst_sql.item_no} in ["REC001A", "REC001"]) and
{020708_counties.COUNTYNM_}="Mecklenburg"
then ({oelinhst_sql.unit_price} * .0725)*{oelinhst_sql.qty_ordered}
else
if {020708_counties.COUNTYNM_} <> "Mecklenburg"
then ({oelinhst_sql.unit_price} * .0675)*{oelinhst_sql.qty_ordered}
 
Looking at the above are you not testing for the same scenario twice?

Each if-then-else statement will select all relevant records the first time they meet a test and not use them later. That's the point of the if-then-else arguement :(

If you are lookign for two different values then consider two seperate formulae, one ofr each evaluation (Unless of course you were just providing example data? Oo)

'J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top