0

我必须从 01-01-2018 到 31-12-2018 插入如下数据。

insert into "schema"."tablename" (FISCAL_DATE,FISCAL_DT,REGION_CD,FISCAL_REGION_CD,FISCAL_DATE1,NEW_REGION_CD) values ('2018-01-01', '2018-01-01','EMEA','EUR','01/01/2018', 'EURO'); 
insert into "schema"."tablename" (FISCAL_DATE,FISCAL_DT,REGION_CD,FISCAL_REGION_CD,FISCAL_DATE1,NEW_REGION_CD) values ('2018-01-01', '2018-01-01','EMEA','EUR','01/01/2018', 'EURO'); 
insert into "schema"."tablename" (FISCAL_DATE,FISCAL_DT,REGION_CD,FISCAL_REGION_CD,FISCAL_DATE1,NEW_REGION_CD) values ('2018-01-01', '2018-01-01','EMEA','EUR','01/01/2018', 'EURO'); 
insert into "schema"."tablename" (FISCAL_DATE,FISCAL_DT,REGION_CD,FISCAL_REGION_CD,FISCAL_DATE1,NEW_REGION_CD) values ('2018-01-01', '2018-01-01','EMEA','EUR','01/01/2018', 'EURO');
...
insert into "schema"."tablename" (FISCAL_DATE,FISCAL_DT,REGION_CD,FISCAL_REGION_CD,FISCAL_DATE1,NEW_REGION_CD) values ('2018-12-31', '2018-12-31','EMEA','EUR','12/31/2018', 'EURO');

是否有任何替代 SQL 语句来实现这一点,否则需要手动更新日期。

请分享您的意见/建议。

4

3 回答 3

0

我已使用以下查询成功插入数据。

insert into "Schema"."tablename" (select to_nvarchar(gen_date, 'YYYY-MM-DD') as fiscal_date,
       to_nvarchar(gen_date, 'YYYY-MM-DD') as fiscal_dt,
       'AMR' as region_cd,
       'AMR' as fiscal_region_cd,
       to_nvarchar(gen_date, 'MM/DD/YYYY') as fiscal_date1,
       'AMR' as led_region_cd
from (
  select generated_period_start as gen_date from SERIES_GENERATE_DATE ('INTERVAL 1 DAY', '2018-01-01', '2018-12-31')
));

谢谢大家的宝贵建议!!

于 2018-10-04T08:42:09.030 回答
0

您还可以在 HANA 数据库上使用 SQL 日期表,使用 SQLScript 创建它非常容易。

请检查以下示例(请根据您的模型替换表名和列名)

do
begin

declare date_start date := '01.01.2018';
declare date_end date := '31.12.2018';

insert into mySampleTransactionData (tdate)
SELECT generated_period_start
 FROM SERIES_GENERATE_DATE('INTERVAL 1 DAY', :date_start, add_days(:date_end,1));

end
于 2018-10-04T05:42:38.170 回答
0

如果我理解正确,您想插入多条记录(每天),日期从2018-01-012018-12-31WHILE您可以使用语句来实现此目的。

DO 
BEGIN

    DECLARE INPUT_DATE date := '2018-01-01';


    WHILE INPUT_DATE <= '2018-12-31'  DO

        INSERT INTO "schema"."tablename" (FISCAL_DATE,FISCAL_DT,REGION_CD,FISCAL_REGION_CD,FISCAL_DATE1,NEW_REGION_CD) values (:INPUT_DATE, :INPUT_DATE,'EMEA','EUR',:INPUT_DATE, 'EURO');

        INPUT_DATE = ADD_DAYS(:INPUT_DATE,1);

    END WHILE;

END
于 2018-10-03T14:14:53.337 回答