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

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.