SQL stored procdure using dates as parameters returning blank rows?

68 Views Asked by At

I am in desperate need of some help!

I am currently working on a project for SQL in a course I am doing (Due on Friday)

One of the questions is to create a stored procedure which shows dates of sales_orders within a certain range.

I have created the following stored procedure for this question, but all I am getting is blank rows? From what I can tell it seems to be reading the dates wrong, but I have no idea why? Can anyone please help? I am a newbie at SQL.

DELIMITER //

CREATE PROCEDURE customer_order_range (start_date DATE, end_date DATE)

BEGIN

SELECT *
FROM customer_order
WHERE `date` >= start_date 
AND `date` <= end_date;

END //

DELIMITER ;


CALL customer_order_range ( 'start_date' = '2020-02-01', 'end_date' = '2020-03-05');

It returns blank rows. My customer_order table has a date column, which is stored as a DATE value.

Any help would be super appreciated!

Conor

2

There are 2 best solutions below

2
On

Remove the delimiters and the columns names like below :

CALL customer_order_range ('2020-02-01', '2020-03-05');
0
On

I've got it!

This piece of the code is wrong:

CALL customer_order_range ( 'start_date' = '2020-02-01', 'end_date' = '2020-03-05');

It should instead be:

CALL customer_order_range ('2020-02-01','2020-03-05');

The problem arose when I put the parameter names in with their values when calling the stored procedure. Thanks everyone! :)