🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.interbase.sql
5 messages
5 total messages Started by Will Bonner-May Mon, 02 Dec 2002 12:20
Percentage in Stored Procedure
#11272
Author: Will Bonner-May
Date: Mon, 02 Dec 2002 12:20
16 lines
1348 bytes
Can anyone help?

I need to work out a score as a percentage within a stored procedure, I am
using the following code but it doesn't seem to work.

(TOPICCOUNT integer,
 TOPICSCOMPLETED integer,
 USERSYLLABUSPROGRESS integer)

.....
UserSyllabusProgress = (:TopicsCompleted / :TopicCount) * 100;
.....

Thanks in advance,

Will Bonner-May
Re: Percentage in Stored Procedure
#11274
Author: Bojidar Alexandrov
Date: Mon, 02 Dec 2002 12:35
30 lines
1700 bytes
Will Bonner-May wrote:
> Can anyone help?
>
> I need to work out a score as a percentage within a stored procedure,
> I am using the following code but it doesn't seem to work.
>
> (TOPICCOUNT integer,
>  TOPICSCOMPLETED integer,
>  USERSYLLABUSPROGRESS integer)
>
> .....
> UserSyllabusProgress = (:TopicsCompleted / :TopicCount) * 100;
> .....
>
> Thanks in advance,
>
> Will Bonner-May

Please read some good sql reference, then Language Reference of Intebase
then ask questions here.

You have faced the problem that your Database is in Dialect 3 and there is
difference with precision of calculations.
What exactly... will leave to you to find out.


--
Bojidar Alexanrov
Kodar Ltd.
http://www.Kodar.net
Re: Percentage in Stored Procedure
#11275
Author: Martijn Tonies
Date: Mon, 02 Dec 2002 12:36
36 lines
1852 bytes
Hi,

> I need to work out a score as a percentage within a stored procedure, I am
> using the following code but it doesn't seem to work.
>
> (TOPICCOUNT integer,
>  TOPICSCOMPLETED integer,
>  USERSYLLABUSPROGRESS integer)
>
> .....
> UserSyllabusProgress = (:TopicsCompleted / :TopicCount) * 100;

My guess is that this will work:

UserSyllabusProgress = (cast(:TopicsCompleted as double precision)/
cast(:TopicCount as double precision)) * 100;

btw - you don't need the ":" here - these are only needed in an SQL statement.


--

With regards,

Martijn Tonies
InterBase Workbench - the developer tool for InterBase
http://www.upscene.com

Firebird Workbench - the developer tool for Firebird
http://www.upscene.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."
Re: Percentage in Stored Procedure
#11277
Author: Arno Brinkman
Date: Mon, 02 Dec 2002 12:38
26 lines
1612 bytes
Hi,

> Can anyone help?
>
> I need to work out a score as a percentage within a stored procedure, I am
> using the following code but it doesn't seem to work.
>
> (TOPICCOUNT integer,
>  TOPICSCOMPLETED integer,
>  USERSYLLABUSPROGRESS integer)
>
> .....
> UserSyllabusProgress = (:TopicsCompleted / :TopicCount) * 100;
> .....
>
> Thanks in advance,

What doesn't seem to work ?

TopicsCompleted and TopicCount are integers. This means the result of (:TopicsCompleted /
:TopicCount) is also an integer. Give this  example a try :

UserSyllabusProgress = (CAST(:TopicsCompleted AS NUMERIC(10,2)) / :TopicCount) * 100;

Regards,
Arno
Re: Percentage in Stored Procedure
#11276
Author: Aage Johansen
Date: Mon, 02 Dec 2002 13:02
28 lines
1629 bytes
Will Bonner-May wrote:
> 
> Can anyone help?
> 
> I need to work out a score as a percentage within a stored procedure, I am
> using the following code but it doesn't seem to work.
> 
> (TOPICCOUNT integer,
>  TOPICSCOMPLETED integer,
>  USERSYLLABUSPROGRESS integer)
> 
> .....
> UserSyllabusProgress = (:TopicsCompleted / :TopicCount) * 100;
> .....


What do you mean by "doesn't seem to work"?  Error message?  Just gives
0?

OtToMH: Will
 UserSyllabusProgress = (cast(:TopicsCompleted as
float)/:TopicCount)*100 
work?
You will probably have to convert it into an integer with rounding or
truncation according to preferences ...

--
Aage J.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads