mysql - Haversine Formula works as Normal SQL but not in stored procedure -


i using haversine formula find distance between users. works normal mysql piece of code. when use same in stored procedure not working , throws 0.00 distances. don't know why?

this working code:

drop temporary table  if exists temp_tab;     create temporary table temp_tab(temp_id integer not null auto_increment primary key,     user_fb_id bigint(20) unique,distance double(15,8) default null) charset=utf8;  insert temp_tab (user_fb_id, distance) select *  (select user_fb_id,               6371 * acos(sin(radians( 11.01684450 )) * sin(radians(`latitude`)) + cos(radians( 11.01684450 )) * cos(radians(`latitude`)) * cos(radians(`longitude`) - radians( 76.95583210 ))) `distance`        `user_login_log`        user_id <>'1831820984'        having `distance` <= 50        order `activity_at` desc) t1 group user_fb_id;  select * temp_tab; 

normal sql output: normal sql output

stored procedure output: stored procedure output

stored procedure:

delimiter ;; create definer=`up_beta`@`127.0.0.1` procedure `usp_geo`(user_id bigint(20),latitude double(15,8),longitude double(15,8), dist int(100),location longtext,page int(2),page_size int(2)) begin      declare limitstart int(10);      declare limitend int(10);       set @user_id=(select user_id);      set @gen=(select gender users user_id=@user_id);      set @latitude = (select latitude);      set @longitude = (select longitude);      set @dist = (select dist);      set @location=(select location);      set limitstart =  ((page*page_size)-page_size);      set limitend =  page_size ;      set @sno = ((page - 1)*page_size);      if @gen='male'         set @gen='female';     else         set @gen='male';     end if;       drop temporary table  if exists temp_tab;     create temporary table temp_tab(temp_id integer not null auto_increment primary key,     user_id bigint(20) unique,distance double(15,8) default null) charset=utf8;  insert temp_tab (user_id, distance) select * (select user_id, 6371 * acos(sin(radians( @latitude )) * sin(radians(latitude)) + cos(radians( @latitude )) * cos(radians(latitude)) * cos(radians(longitude) - radians( @longitude ))) `distance` `user_log` user_id <>@user_id having `distance` <= @dist order `activity_at` desc) t1 group user_id;    select * temp_tab;  drop temporary table  if exists search_tab;     create temporary table search_tab(temp_id integer not null auto_increment primary key,     user_id bigint(20) unique,name varchar(500),gender varchar(100),     town longtext,current_location longtext default null,is_in_app tinyint(4) default 0,distance double(15,8)) charset=utf8;  insert search_tab(user_id,name,gender,town,distance)  select a.user_id, a.name,a.gender,a.home_town,b.distance users a, temp_tab b a.user_id = b.user_id , a.gender=@gen , a.relationship_id not in(2,3,4);    if @location<>'' , @location<>null         begin             set @city=(select concat('''','%',@location,'%',''''));              set @gender =(select concat('''',@gen,''''));             set @insert_sql = concat('insert ignore search_tab(user_id,name,gender,town,location) select a.user_id, a.name,a.gender,a.home_town,b.current_location users a, user_details b b.current_location ',@city,' , a.id = b.user_id , a.gender=',@gender,' , a.relationship_id not in(2,3,4)');              prepare stmt1 @insert_sql;             execute stmt1;          end;  end if;    update search_tab  set is_in_app=1 user_fb_id in     (select user_id users access_token not null);        select  @a:=@a+1 sno,user_id,name,gender,town,current_location,is_in_app,distance     search_tab ,(select @a:= @sno)     limit limitstart,limitend;      select count(temp_id)as total_count search_tab;   end;; delimiter ; 


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -