Reputation: 101
DELIMITER //
CREATE PROCEDURE GetWinners(IN Number INTEGER , IN Table_Name VarChar(7))
BEGIN
SET @t1 = CONCAT('Select * FROM ', Table_Name, ' Where number = ', Number, ' && active = true && dateAndTime < 2015-02-10');
PREPARE stmt3 FROM @t1;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;
END //
DELIMITER ;
dateAndTime is a column where I store DateTime values.
I can't understand why with && dateAndTime < 2015-02-10'
, the query returns no results.
If I remove && dateAndTime < 2015-02-10'
, then some results are returned.
This happens even though I have DateTime value lower than 2015-02-10 in the columns.
Upvotes: 1
Views: 1109
Reputation: 301
This most probably due to your date format, the time is added to the date but due to your preferences in mysql, it only shows the date without time.
Use trim
or trunc
to remove the time.
TRUNC(dateAndTime) < TO_DATE('2015-02-10', 'YYYY-MM-DD')
Upvotes: 1
Reputation: 737
Surround your DateTime in single quotes
SET @t1 = CONCAT('Select * FROM ', Table_Name, ' Where number = ', Number, ' && active = true && dateAndTime < '2015-02-10'');
Upvotes: 0