修改完整版的sql存储(积分兑换脚本),改写出可执行的shell create procedure "rptdev"."sp_wjq_jf_value_dhfz_show"( in @data_date integer default cast("dateformat"("now"()-1,'yyyymmdd') as integer), in @is_run_flag1 integer default 1, in @is_run_flag2 integer default 10 ) on exception resume /****************************************************************** -- Purpose : 兑换积分分析报表 -- Auther: xxx -- Date : 20210923 *******************************************************************/ begin declare @stat_date varchar(8); --统计日期 declare @month_id integer; --统计月份 declare @month_first_date varchar(8); --统计月的第一天 declare @month_last_date varchar(8); --统计月的最后一天 declare @last_month_first_date varchar(8); --上月的第一天 declare @last_month_last_date varchar(8); --上月的最后一天 declare @last_month integer; --上月 declare @last_last_month integer; --上上月 declare @last_month_this_day varchar(8); --上月当天 declare @last_year_this_month integer; --上年当月 declare @this_year_first_month integer; --本年首月 declare @last_year_last_month integer; --上年尾月 set @stat_date = convert(varchar(8),@data_date); set @month_id = @data_date/100; set @month_first_date = "dateformat"(@data_date,'yyyymm01'); --统计月的第一天 set @month_last_date = "dateformat"("dateadd"("dd",-1,"dateformat"("dateadd"("mm",1,@data_date),'yyyymm01')),'yyyymmdd'); --统计月的最后一天 set @last_month_first_date = "dateformat"("dateadd"("mm",-1,@data_date),'yyyymm01'); --上月第一天 set @last_month_last_date = "dateformat"("dateadd"("dd",-1,"dateformat"("dateadd"("mm",1,@data_date),'yyyymm01')),'yyyymmdd'); set @last_month = cast("dateformat"("dateadd"("month",-1,@data_date),'yyyymm') as integer); --上月 set @last_last_month = cast("dateformat"("dateadd"("month",-2,@data_date),'yyyymm') as integer); --上上月 set @last_month_this_day = "dateformat"("dateadd"("mm",-1,convert(date,@data_date)),'yyyymmdd'); --上月当天 set @last_year_this_month = convert(integer,"dateformat"("dateadd"("yy",-1,@last_month_this_day),'yyyymm')); --上年当月 set @this_year_first_month
时间: 2023-07-23 17:28:22 浏览: 97
Here's a modified version of the SQL code in a shell script that can be executed:
```
#!/bin/bash
mysql -u <username> -p<password> -e "CREATE PROCEDURE rptdev.sp_wjq_jf_value_dhfz_show(
IN data_date INTEGER DEFAULT CAST(DATE_FORMAT(NOW() - INTERVAL 1 DAY, '%Y%m%d') AS INTEGER),
IN is_run_flag1 INTEGER DEFAULT 1,
IN is_run_flag2 INTEGER DEFAULT 10
)
BEGIN
DECLARE stat_date VARCHAR(8);
DECLARE month_id INTEGER;
DECLARE month_first_date VARCHAR(8);
DECLARE month_last_date VARCHAR(8);
DECLARE last_month_first_date VARCHAR(8);
DECLARE last_month_last_date VARCHAR(8);
DECLARE last_month INTEGER;
DECLARE last_last_month INTEGER;
DECLARE last_month_this_day VARCHAR(8);
DECLARE last_year_this_month INTEGER;
DECLARE this_year_first_month INTEGER;
DECLARE last_year_last_month INTEGER;
SET stat_date = CONVERT(VARCHAR(8), data_date);
SET month_id = data_date / 100;
SET month_first_date = DATE_FORMAT(data_date, '%Y%m01');
SET month_last_date = DATE_FORMAT(DATE_ADD(DATE_FORMAT(DATE_ADD(data_date, INTERVAL 1 MONTH), '%Y%m01'), INTERVAL -1 DAY), '%Y%m%d');
SET last_month_first_date = DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), '%Y%m01');
SET last_month_last_date = DATE_FORMAT(DATE_ADD(DATE_FORMAT(DATE_ADD(data_date, INTERVAL 1 MONTH), '%Y%m01'), INTERVAL -1 DAY), '%Y%m%d');
SET last_month = CAST(DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), '%Y%m') AS INTEGER);
SET last_last_month = CAST(DATE_FORMAT(DATE_ADD(data_date, INTERVAL -2 MONTH), '%Y%m') AS INTEGER);
SET last_month_this_day = DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), '%Y%m%d');
SET last_year_this_month = CONVERT(INTEGER, DATE_FORMAT(DATE_ADD(last_month_this_day, INTERVAL -1 YEAR), '%Y%m'));
SET this_year_first_month = CAST(DATE_FORMAT(CONCAT(YEAR(data_date), '0101'), '%Y%m') AS INTEGER);
SET last_year_last_month = CAST(DATE_FORMAT(DATE_ADD(CONCAT(YEAR(data_date), '0101'), INTERVAL -1 DAY), '%Y%m') AS INTEGER);
END;"
```
Note: Replace `<username>` and `<password>` with your MySQL username and password respectively.
阅读全文