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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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" <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 |
|
|||
|
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 |
|
|||
|
"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 |
|
|||
|
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 |