truncate within stored procedure?

This is a discussion on truncate within stored procedure? within the MySQL Database forums, part of the Database Forums category; I need to create a stored procedure for mysql 5 that does some simple math on a passed parameter before ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-02-2007
Jeff
 
Posts: n/a
Default 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

Reply With Quote
  #2 (permalink)  
Old 06-02-2007
Jeff
 
Posts: n/a
Default Re: truncate within stored procedure?


"Jeff" <none@nothingX.com> wrote in message
news:4660e913$0$16302$88260bb3@free.teranews.com.. .

Never mind. I figured it out.



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

Reply With Quote
  #3 (permalink)  
Old 06-04-2007
PeterD
 
Posts: n/a
Default Re: truncate within stored procedure?

Jeff <none@nothingX.com> wrote:

> "Jeff" <none@nothingX.com> wrote in message
> news:4660e913$0$16302$88260bb3@free.teranews.com.. .
>
> Never mind. I figured it out.


So what was your solution?

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
Reply With Quote
  #4 (permalink)  
Old 06-04-2007
Jeff
 
Posts: n/a
Default Re: truncate within stored procedure?


"PeterD" <pd.news@dsl.pipex.invalid> wrote in message
news:1hz6glk.11lj7qnlupflN%pd.news@dsl.pipex.inval id...
> Jeff <none@nothingX.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


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 documenation and took me a long time to locate.

Jeff



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

Reply With Quote
  #5 (permalink)  
Old 06-06-2007
Carlos Troncoso
 
Posts: n/a
Default Re: truncate within stored procedure?

On 4 jun, 09:38, "Jeff" <n...@nothingX.com> wrote:
> "PeterD" <pd.n...@dsl.pipex.invalid> wrote in message
>
> news:1hz6glk.11lj7qnlupflN%pd.news@dsl.pipex.inval id...
>
> > Jeff <n...@nothingX.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

>
> 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 documenation and took me a long time to locate.
>
> Jeff
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com


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
Asociación Chilena de Seguridad



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:22 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0