开发者

get current date in stored procedure in mysql

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 B开发者_如何学编程Y '"'    
            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

  1. INTO OUTFILE '/appdata/reports01/result.csv' must be like "INTO OUTFILE '/appdata/reports01/result-current-timestamp.csv'
  2. 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.

DECLARE outfile_name varchar(300);

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜