I need to make a query in MySQL setting 3 variables, when I know in the case of integer number of the right one, more when I include data ta returning empty.
Follow my query , what could be doing wrong?
SET @tipo = 47;
SET @dataini = 2016-03-17;
SET @datafin = 2016-03-17;
SELECT
*
FROM sale
WHERE start_time BETWEEN '@dataini' AND '@datafin'
AND sale_type = @tipo
The result of the query follows without using the variables:
2 44 346479 2016-03-17 17:44:58 0 0 47 0 10.000 0.000 0 0 395 0 0.000 0.000 0.000 11962677.200 0.000 2016-03-17 16:47:51 2016-03-17 17:44:58 2016-03-17 0 0 0 0.000 0 0 0 1458243445 1458243508 1458244061
2 44 346483 2016-03-17 17:55:56 0 0 47 0 10.000 10.000 0 0 395 35 0.000 0.000 0.000 11962677.200 0.000 2016-03-17 16:58:57 2016-03-17 17:55:56 2016-03-17 0 0 0 0.000 0 0 0 1458244642 1458244678 1458244720
2 44 346510 2016-03-17 18:48:33 0 0 47 0 10.000 10.000 0 0 621 0 0.000 0.000 0.000 11962906.700 0.000 2016-03-17 17:51:38 2016-03-17 18:48:33 2016-03-17 0 0 0 0.000 0 0 0 1458247805 1458247848 1458247877
2 44 346513 2016-03-17 18:50:29 0 0 47 0 10.000 0.000 0 0 621 0 0.000 0.000 0.000 11962906.700 0.000 2016-03-17 17:53:25 2016-03-17 18:50:29 2016-03-17 0 0 0 0.000 0 0 0 1458247931 1458247977 1458247992