wubblyjuggly
wubblyjuggly

Reputation: 969

Trying to get Count single value from mysql stored procedure

I am trying to do a count in a mysql stored procedure but cant get the syntax right help1

    delimiter//
create procedure get_count_workmen_type(
    IN employee_payroll int,    
    OUT mycount int
)


begin 

SELECT count(*) into mycount from workman
where employee_payroll = employee_payroll

end //
delimiter;

Upvotes: 0

Views: 58

Answers (1)

Ike Walker
Ike Walker

Reputation: 65567

You should prefix your parameter names (personally I use "p_") to differentiate them from column names, etc. For example where employee_payroll = employee_payroll will always be true because it's comparing the column to itself.

Also you should add a semi-colon to the end of your select statement.

Putting those two changes together gives you something like this:

delimiter //

create procedure get_count_workmen_type(
    IN p_employee_payroll int,    
    OUT p_mycount int
)
begin 
  SELECT count(*) 
  into p_mycount 
  from workman
  where employee_payroll = p_employee_payroll;
end //

delimiter ;

Upvotes: 1

Related Questions