0
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`(out myvalue int)
BEGIN
select count(*) from EventList_View group by eventId  into myvalue  ;
END

this is my Procedure i am calling this Procedure call test(@output); select @output; like this but i am unable to get value of output parameter as myvalue . while i am trying to execute select count(*) from EventList_View group by eventId this query i am getting value 5 please tell me how to get output value where am doing wrong in procedure .

Ramy
  • 172
  • 1
  • 17
Dev Research
  • 61
  • 2
  • 12
  • Do Tag which are related only to your Question. I think SQL Server Tag doesn't suits your query. – Shakeer Mirza Oct 20 '16 at 04:46
  • Possible duplicate of [mysql stored-procedure: out parameter](http://stackoverflow.com/questions/1113579/mysql-stored-procedure-out-parameter) –  Oct 20 '16 at 05:04
  • That is a horrible select stmt you have going there. Do you see why? – Drew Oct 20 '16 at 05:14
  • Well then let me tell ya. When you have more than one value of eventId in the table, you will get `Error Code: 1172. Result consisted of more than one row` – Drew Oct 20 '16 at 05:22
  • NO its contain only one count – Dev Research Oct 20 '16 at 05:24
  • It doesn't matter. You should not write code that could return more than one row of data into a variable set (in your case just 1 variable). And if your table only ever contains one distinct value for eventId in a table, why have it there anyway as a column. This is simple. Your code will blow up with an 1172 in the real world. – Drew Oct 20 '16 at 05:24

1 Answers1

2
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`(out myvalue int)
BEGIN
select count(*) from (select * from events group by event_id) as totalcount into myvalue;


END

apply this query

Research Development
  • 884
  • 1
  • 19
  • 39