I have created a stored procedure in mysql
DELIMITER //
CREATE PROCEDURE simpleproc ()
BEGIN
SELECT YEAR(dtm),
WEEK(dtm),
b.x_title,
COUNT(b.x_id)
INTO OUTFILE '/appdata/reports01/result.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM tbla a
JOIN tblb b ON b.x_id = a.x_id
WHERE plan_grp_id IN (10031, 10034)
AND dtm > '20110101'
GROUP BY YEAR(dtm), WEEK(dtm), a.x_id;
END //
delimiter ;
I need to do two things
INTO OUTFILE '/appdata/reports01/result.csv'must be like “INTO OUTFILE ‘/appdata/reports01/result-current-timestamp.csv’- dtm > ‘20110101’ must be dtm > CURDATE() + 0 .
This:
SELECT CURDATE() + 0
…gets me the format ‘20110101’, but I can’t use that in the query like dtm > CURDATE() + 0
Use variables.
Get the current timestamp and append it to the remaining part of the string.
Use INTO keyword to get the output of the SELECT statement into a variable.
Use CONCAT() for concatinating 2 strings.