Jump to content

convert float to int

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
ankimo

ankimo

    Newbie

  • Members
  • Pip
  • 3 posts
Hi, all.

I'm in the process of creating a function called, split_tables. One issue I'm having is that when I set a value called @half_records by dividing @all_records in 2, the value ends up as a float.

But I need that value in a limit clause. How do I convert @half_records to an int?

DROP PROCEDURE if exists split_tables;


delimiter $$

CREATE PROCEDURE split_tables(in_table varchar(255), in_file varchar(255))


BEGIN

  declare all_records int default 0;

  declare half_records int default 0;


  set @my_query=concat('select count(*) into @all_records from ', in_table);

  prepare s1 from @my_query;

  execute s1;

  deallocate prepare s1;



  set @half_records = @all_records/2;

  set @my_query=concat('create table ', in_table, '1 select * from ', in_table, 'limit ', @half_records);

  prepare s2 from @my_query;

  execute s2;

  deallocate prepare s2;


END$$

delimiter ;


Thanks.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Which database platform are you using?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
ankimo

ankimo

    Newbie

  • Members
  • Pip
  • 3 posts
sorry about that. i'm using mysql.

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
I'm not sure it works at the limit field in a simple query, but I'll try the round() function

select * from my_table limit round(23.45)