MySQL Forums
Forum List  »  Stored Procedures

DAYNAME problem using CASE statement
Posted by: John Noble
Date: May 07, 2020 06:12AM

Hi folks,

Im having difficulty in determining the dayname on a stored proc.
Here is my proc.

CREATE DEFINER=`root`@`%` PROCEDURE `usp_SalesHistoryFrenchTransportDocsTest`(
IN p_despatchDate date

SELECT CASE salesHistory.despatchDate WHEN DAYNAME(p_despatchDate) = "Saturday" THEN
DATE_ADD(salesHistory.despatchDate, INTERVAL 2 DAY)
DATE_ADD(salesHistory.despatchDate, INTERVAL 1 DAY) END as despatchDate FROM salesHistory
WHERE saleshistory.despatchDate = p_despatchDate;


When I use call usp_SalesHistoryFrenchTransportDocsTest('2020-04-04') (which is a Saturday), I expect the data to add 2 days on to it. But it always adds 1 day. It does not seem to to be catching on the first case statement.

What am I missing here?


Options: ReplyQuote

Written By
DAYNAME problem using CASE statement
May 07, 2020 06:12AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.