0
I need to search details of a table creating a precedent and using month and year as variables, but I do not know how I could do it, the column dataPedido is defined as Datetimethought about something like this, but I have no idea what to put after "LIKE".
DELIMITER $$
CREATE PROCEDURE buscaPedido(IN y int, m int)
BEGIN
DECLARE Y, M INT;
SET @Y =y ,@M = m;
SELECT * FROM pedido
WHERE dataPedido LIKE ... ;
END;
$$
If your field is of type DATETIME then you should not use LIKE to compare. If you only want month and year then use the EXTRACT function to get the month and year and compare using the equal operator.
– anonimo
Got it here, now I need to search a date range using month and day
– Thiago Souza
Then I think you should study about the operator BETWEEN. https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_between
– anonimo