Professional Web Applications Themes

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. #1

    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

    Jeff Guest

  2. #2

    Default 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. #3

    Default Re: truncate within stored procedure?

    Jeff <com> wrote:
     

    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 Guest

  4. #4

    Default 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. #5

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



    Carlos Guest

Similar Threads

  1. Stored Procedure Help
    By drudiggy in forum Coldfusion Database Access
    Replies: 11
    Last Post: November 29th, 08:44 PM
  2. need help on a stored procedure
    By Helixpoint in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 8th, 01:26 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139