4

我需要帮助我如何将类型@todayCURRENT_DATE()值保存到我的变量中,VARCHAR正如您在第一个 SET 行和变量的第二行中看到的那样,我@yesterday想将值保存为 DATE 类型。

SET @today=CAST(CURRENT_DATE() AS VARCHAR(50)),
@yesterday=CAST(DATE_ADD(CURRENT_DATE, INTERVAL -1 DAY) AS DATE)

SELECT @today, @yesterday

谢谢你的帮助

4

1 回答 1

5

这可能会有所帮助:

SELECT CAST(CURRENT_DATE() AS CHAR(50)) INTO @today;
SELECT CAST(DATE_ADD(CURRENT_DATE, INTERVAL -1 DAY) AS DATE) INTO @yesterday;

SELECT @today, @yesterday

编辑:您的版本也可以,但您不能转换为 VARCHAR()

SET @today=CAST(CURRENT_DATE() AS CHAR(50)) , 
@yesterday=CAST(DATE_ADD(CURRENT_DATE, INTERVAL -1 DAY) AS DATE) ;
于 2013-09-12T18:41:51.160 回答