# truncate within stored procedure? - MySQL

I need to create a stored procedure for mysql 5 that does some simple math on a passed parameter before storing it. I can get everything working with one exception: I need to truncate the results of a division. e.g., 10/3 needs to be equal to 3 and not 3.33. The two lines below work, declare xx int; set xx = (par/3); but this does not, there apparently is no truncate function in mysql. declare xx int; set xx = trunc(par/3); How might I do this? Thanks Jeff -- Posted via a free Usenet account from http://www.teranews.com...

1. ## truncate within stored procedure?

I need to create a stored procedure for mysql 5 that does some simple math
on a passed parameter before storing it.

I can get everything working with one exception:

I need to truncate the results of a division.

e.g., 10/3 needs to be equal to 3 and not 3.33.

The two lines below work,
declare xx int;
set xx = (par/3);

but this does not, there apparently is no truncate function in mysql.
declare xx int;
set xx = trunc(par/3);

How might I do this?

Thanks

Jeff

--
Posted via a free Usenet account from http://www.teranews.com

Jeff Guest

2. ## Re: truncate within stored procedure?

"Jeff" <com> wrote in message
news:4660e913\$0\$16302\$teranews.com...

Never mind. I figured it out.

--
Posted via a free Usenet account from http://www.teranews.com

Jeff Guest

3. ## Re: truncate within stored procedure?

Jeff <com> wrote:

If you had this problem, then someone else might also have the problem
and if they search newsgroups for the same problem, all they'll find is
your original problem, and that you found a solution, but no solution
given.

--
Pd
PeterD Guest

4. ## Re: truncate within stored procedure?

"PeterD" <pipex.invalid> wrote in message
news:1hz6glk.11lj7qnlupflN%pipex.invalid...

Most languages like the vb.net that call the procedure use something along
the lines of trunc(variablename).(although I found that vb.net actually uses
something like Int(variablename).

The mysql stored procedures require something like, truncate(variablename,0)

where the 0 indicates no decimal points.

....this was burried in the doenation and took me a long time to locate.

Jeff

--
Posted via a free Usenet account from http://www.teranews.com

Jeff Guest

5. ## Re: truncate within stored procedure?

On 4 jun, 09:38, "Jeff" <com> wrote:

>
> Most languages like the vb.net that call the procedure use something along
> the lines of trunc(variablename).(although I found that vb.net actually uses
> something like Int(variablename).
>
> The mysql stored procedures require something like, truncate(variablename,0)
>
> where the 0 indicates no decimal points.
>
> ...this was burried in the doenation and took me a long time to locate.
>
> Jeff
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com[/ref]

Anyway, there IS an operator in MySql that can handle an INTEGER
DIVISION. = DIV.

Let's say you want to get only the integer (not the decimals) of a
division.

N=12
M=5

1: the long way
Select (Floor(N/M)) as Result;

2: the Neat way
Select (N DIV M) AS Result;

have a good one!

Carlos Troncoso Phillips
Gerencia de Operación y Gestión

Carlos Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•