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!

Dividing price by item number

Status
Not open for further replies.

lbizzell

Technical User
Apr 22, 2005
30
0
0
US
Hello,
Thanks all for the help... it's starting to make sense and I'm picking up a few books this weekend as well. I have one more question. Crystal 9 with SQL. I've created a crosstab report and need to decrease the extended price by 50% for certain items, the rest to remain at 100%.
example:
Item Extended Price
K0040009 $140.00
M1370013 $376.00

I tried adding this line to the extened price formula {co_ship.qty_shipped}*{coitem.price}... but it didn't work

if {coitem.item}='K0040009' then (({coitem.price}*{co_ship.qty_shipped})/2) else

Any help would be appreciated.
Thanks-
Lauri
 
Try posting the entire formula, this ends in ELSE...

Is this what you seek?:

if {coitem.item}='K0040009' then
(({coitem.price}*{co_ship.qty_shipped})/2)
else
{coitem.price}*{co_ship.qty_shipped}

Generally it's best to post:

Crystal version
Database/connectivity used
Example data
Expected output

-k
 
synapsevampire-
Yes, that is the formula that I used, but it doesn't work.

Crystal 9 with SQL.

Decrease the extended price by 50% for certain items, the rest to remain at 100%.

example:
Item Extended Price
K0040009 $140.00
M1370013 $376.00

Output:
Item Extended Price
K0040009 $70.00
M1370013 $376.00

Thanks!
Laurie
 
Sorry - no error message, just output of:
Item Extended Price
K0040009 $140.00
M1370013 $376.00

Thanks-
Laurie
 
Edit your formula for extended price, adding a /2 at the end. Place this formula in the crosstab, and remove your existing formula/database field.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
I don't undersatand why it isn't working, I would guess that the if {coitem.item}='K0040009' part isn't working, so try:

if {coitem.item}='K0040009' then
(({coitem.price}/2)*{co_ship.qty_shipped}) & " halved"
else
{coitem.price}*{co_ship.qty_shipped}& " whole price"

If you see the halved text the price should be 50%.

-k
 
Thanks- it worked this morning!

Thanks again for all your help.
Laurie
 
Laurie,

Nice to hear that you solved your problem, but here is something that may be of help in the future.

I discovered just today, that a few of my reports had erroneous results. I finally tracked it down to the division of integer-type numbers:

Case 1: Select 2 / 3 returns a zero!!!
Case 2: Select 2.0 / 3 correctly returns .666666

So if your qty_shipped field is an integer (or smallint, or tinyint) and you divided it with another integer number (2), this would evaluate to zero.

So the solution to your problem may be:
Solution 1: qty_shipped / 2.0 or
Solution 2: cast(qty_shipped as decimal)/2 or
Solution 3: cast(qty_shipped as real)/2

Ron
 
I forgot to add that I am using MS SQL Server 7.0
Ron
 
Romspree has a good point.

You might want to add some error trapping in your formula to make sure you don't get a division by zero result or anything else fishy. Check to make sure the output is an actual number.

If it didn't work yesterday, but works this morning and you didn't do anything to it, it could be that there was a row with some data that just didn't work out right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top