|
-
Jun 22nd, 2000, 04:42 AM
#1
Thread Starter
Addicted Member
why is this causing a divide by 0 error???
update #totals
set units_cancel_percent = units_sent/units_cancelled
in my temp table I am trying to divide the results of these two colums by each other in an update statement; how can I do this????
-
Jun 22nd, 2000, 04:54 AM
#2
transcendental analytic
units_cancelled is probably 0 then...
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 22nd, 2000, 04:56 AM
#3
Thread Starter
Addicted Member
i don't understand meanig it was trying to divide by 0 how can i work around this problem????
-
Jun 22nd, 2000, 04:59 AM
#4
New Member
If your units_cancelled variable could be zero, you need to use an if_then statement to check it before the computation.
If units_cancelled = 0 then
units_cancel_percent = 0
else
set units_cancel_percent = units_sent/units_cancelled
-
Jun 22nd, 2000, 05:24 AM
#5
You need to use an expression in your update statement. I know that in Access SQL (Jet), you can use VB functions (such as iif) within the SQL statement, such as this:
update #totals
set units_cancel_percent =
iif(units_cancelled = 0, 0, units_sent/units_cancelled)
If you are using SQL Server or other database, look into the allowable functions. I'm looking at a SQL Server book right now, and I see that you can do something like this:
update #totals
set units_cancel_percent =
case units_cancelled
when 0 then 0
else units_sent/units_cancelled
end
I hope this was helpful.
"It's cold gin time again ..."
Check out my website here.
-
Jun 22nd, 2000, 06:11 AM
#6
Thread Starter
Addicted Member
this seems to work:
update #totals
set units_shipped_day1_percent = units_sent/units_shipped_day1
where units_shipped_day1 <> 0
and units_shipped_day1 is not null
but how do i get the results to return a percentage??? and have the % on it??????
Let me know if there is a better way to code this too????
thanks
-
Jun 22nd, 2000, 07:00 AM
#7
transcendental analytic
Code:
set units_shipped_day1_percent = 100*units_sent/units_shipped_day1 & "%"
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 22nd, 2000, 08:19 AM
#8
Thread Starter
Addicted Member
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '%' to a column of data type int
get this error anyway around it???
-
Jun 22nd, 2000, 07:58 PM
#9
Thread Starter
Addicted Member
does anyone know how to get his to be a percentage - converted to a char ? and add the % on to it?????
THANKS!!!
-
Jun 22nd, 2000, 09:56 PM
#10
Addicted Member
I don't know much about Jet Databases but why don't you store the data as a decimal, and just convert when you retrieve and want to display your data... ?
-
Jun 22nd, 2000, 11:37 PM
#11
Thread Starter
Addicted Member
okay so the column is a decimal how do i then convert the syntax can you give an example thanks
-
Jun 22nd, 2000, 11:56 PM
#12
Addicted Member
You need to use the 'Format' function.
For instance, if you have your value in a Variable called dTemp, you can diplay it in a MsgBox like that:
Code:
dTemp = 0.003521
MsgBox "You precentage is: " & Format(dTemp, "#0.000%")
Yopu can experiment with the format itself to find what suits your needs.
-
Jun 23rd, 2000, 08:13 PM
#13
Hyperactive Member
Calculating percent
Hi,
I think your formula is wrong. It should be:
set units_cancel_percent = (units_cancelled/units_sent)*100
This will give you the percent of cancelled orders.
e.g.
250 units sent
25 units cancelled
25/250 = 0.1
0.1*100 = 10
10% of the units were cancelled
The only time you'd get a divide-by-zero error is if units_sent was zero.
Al.
A computer is a tool, not a toy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|