我有以下查询:
SELECT t6.USERNAME Nombre, t2.RESOURCENAME Recurso, RESERVATION_DESCRIPTION Descripción,
DATE_FORMAT(RESERVATIONDUEDATE, '%M %D %Y de %l:%i %p') + ' a ' +
DATE_FORMAT(RESERVATIONEXPIREDATE, '%;:%i %p') Fecha
FROM `reservation` t1
INNER JOIN `resource` t2 ON t1.RESOURCEID = t2.RESOURCEID
INNER JOIN schedule_intermediate t3 ON t1.SCHEDULEID_GENERATED = t3.SCHEDULEID_GENERATED
INNER JOIN class t4 ON t1.CLASSID = t4.CLASSID
INNER JOIN grade t5 ON t1.GRADEID = t5.GRADEID
INNER JOIN users t6 ON t1.USERID = t6.USERID
WHERE (YEARWEEK(`RESERVATIONDUEDATE`, 1) = YEARWEEK(CURDATE(), 1)) AND (t2.RESOURCELOCATIONID = 3 OR t2.RESOURCELOCATIONID = 4),
CAST(Fecha as char)
然而, Cast无效,说它有语法错误。如何将名为Fecha
的字段强制转换为字符串?
答案 0 :(得分:1)
完全不清楚CAST(Fecha as char)
条款中WHERE
正在做什么。也许你可以删除它:
WHERE (YEARWEEK(`RESERVATIONDUEDATE`, 1) = YEARWEEK(CURDATE(), 1)) AND
(t2.RESOURCELOCATIONID IN (3, 4)
但是,您还需要更改SELECT
中的表达式。 +
是补充,而不是字符串连接:
SELECT t6.USERNAME Nombre, t2.RESOURCENAME Recurso, RESERVATION_DESCRIPTION Descripción,
CONCAT(DATE_FORMAT(RESERVATIONDUEDATE, '%M %D %Y de %l:%i %p'), ' a ',
DATE_FORMAT(RESERVATIONEXPIREDATE, '%;:%i %p')
) as Fecha