Jump to content

[SOLVED] stored procedure .. how to pass variable.?


fird01

Recommended Posts

delimiter |
create procedure totalmonth(btnid int, mnth int)
begin
select count(click) as total from eachclick where date like "%-mnth-%" and btn=btnid;
end
|
delimiter;

 

my table would look like this

 

eachclick

+--+---+----+--------------+

|bil |btn|click|date              |

+--+----+----+--------------+

|1  | 2  |  1  | 2008-05-01    |

+--+---+----+--------------+

so i create a stored procedure in my database... the thing is.. how do i pass mnth value to the query in procedure...

 

 

 

nope not because in/out thing.. solve it already

 

create procedure totalmonth(btnid integer(10),mnth varchar(10))
begin
declare a varchar(20);
set @a=concat('%-',mnth,'-%');
select count(click) as total from eachclick where btn=btnid and date like @a ;
end

 

eventually when i used

call totalmonth(2,05);

 

it not actually passing 05 as the value.. it actually passing 5 as the value...

 

so when i declare the variable as varchar and put a qoute to 05 when calling the procedure

 

call totalmonth(2,"05");

 

and it worked.. thx anyway..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.