N
N
nkorobkov2017-04-05 11:10:05
MySQL
nkorobkov, 2017-04-05 11:10:05

How to create a SQL procedure correctly?

Good morning. There is such a database:
036edc62f83f4a6d9c2fb60571344f48.png
I want to create a procedure for it that will return the cost of a certain service from an enterprise with a given name. Those. I pass the name of the company and the name of the service into it, and it returns a table with the columns: the name of the company I specified, the name of the service, and the cost.
Here's how I'm trying to do it, but apparently I made a mistake somewhere and it doesn't work for me:

CREATE PROCEDURE get_cost(org_name, service_name)
BEGIN
    SELECT organizations.org_name, services_list.service_name, org_services.service_cost 
        FROM organizations, services_list, org_services WHERE organizations.ID = 
        org_services.org_id AND services_list.ID = org_services.service_id
        HAVING organizations.org_name = org_name AND services_list.service_name = service_name;
END

Please tell me what is wrong and how can I fix it or implement it differently...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-04-05
@nkorobkov

Why is there a procedure for this? A normal request is enough
. And why return the names of the organization and service from the request if they were just passed there?

SELECT `os`.`service_cost`
  FROM `Org_services` AS `os`
  JOIN `Organizations` AS `o` ON `o`.`ID` = `os`.`org_id` AND `o`.`org_name` = :orgName
  JOIN `Services_list` AS `s` ON `s`.`ID` = `os`.`service_id` AND `s`.`service_name` = :servName

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question