QLIKVIEW如何写增量加载脚本

Qlikview增量加载数据库里的数据到QVD文件。

MainTab:

LET LastReload=reloadtime();

LET Curr=now();

TRACE <<<<< Current Time is $(Curr), Last Reload Time is $(LastReload)>>>>>;

SET ThousandSep=‘,‘;MainTab:

LET LastReload=reloadtime();

LET Curr=now();

TRACE <<<<< Current Time is $(Curr), Last Reload Time is $(LastReload)>>>>>;

SET ThousandSep=‘,‘;

SET DecimalSep=‘.‘;

SET MoneyThousandSep=‘,‘;

SET MoneyDecimalSep=‘.‘;

SET MoneyFormat=‘$#,##0.00;($#,##0.00)‘;

SET TimeFormat=‘h:mm:ss TT‘;

SET DateFormat=‘YYYY-MM-DD‘;

SET TimestampFormat=‘YYYY-MM-DD h:mm:ss[.fff] TT‘;

SET MonthNames=‘Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec‘;

SET DayNames=‘Mon;Tue;Wed;Thu;Fri;Sat;Sun‘;

//setvQvdFolder=‘D:\Manie\ABC\QV_REPORT\PLS\QVD‘;

set vQvdFolder=‘D:\Watson\ABC\QV_REPORT\BDS\QVD‘; //The location is on Watson‘s own PC

SET vDBName=‘DW‘;

//OLEDB CONNECT TO[Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;DataSource=192.168.2.250;Use Procedure for Prepare=1;Auto Translate=True;PacketSize=4096;Workstation ID=8BFWC02;Use Encryption for Data=False;Tag with columncollation when possible=False];

//ODBC CONNECT32 TO DW;

//OLEDB CONNECT32 TO[Provider=SQLOLEDB.1;Persist Security Info=False;User ID=vscmis;InitialCatalog=DW;Data Source=192.168.2.250;Use Procedure for Prepare=1;AutoTranslate=True;Packet Size=4096;Workstation ID=R9HDET7;Use Encryption forData=False;Tag with column
collation when possible=False];

OLEDB CONNECT32 TO [Provider=SQLOLEDB.1;Persist Security Info=False;UserID=vscmis;Initial Catalog=DW;Data Source=192.168.2.250;Use Procedure forPrepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=R9HDET7;UseEncryption for Data=False;Tag with column
collation when possible=False];

IF Month(now())>=4 THEN

LET vStartYear=Year(now())-2;

ELSE

LET vStartYear=Year(now())-3;

ENDIF;

SET vMonthDay=‘04-01‘;

LET vStartDate=Date(‘$(vStartYear)-$(vMonthDay)‘,‘YYYY-MM-DD‘);//num(Date(‘$(vStartYear)-$(vMonthDay)‘,‘YYYY-MM-DD‘));

LET vEndDate=Date(today()-1,‘YYYY-MM-DD‘);//num(today()-1);num(Date(‘2012-04-18‘,‘YYYY-MM-DD‘));

Trace <<<<<Period: From $(vStartDate) to $(vEndDate) >>>>>;

Transaction Tab:

MeasureTable:

LOAD

* INLINE

[Measure

ABC_BI_INV_LINES

ABC_BI_INV_HEADERS

];

FOR counter = 1 to NoOfRows(‘MeasureTable‘)  //FORcounter = 1 to NoOfRows(‘SourceTable‘)

LET vSourceName=Fieldvalue(‘Measure‘, $(counter));

IF ‘$(vSourceName)‘=‘ABC_BI_INV_HEADERS‘ THEN

SET DateField=‘INVOICE_DATE‘;

ELSE

SET DateField=‘TRX_DATE‘;

ENDIF;

For Date = num(‘$(vStartDate)‘) to num(‘$(vEndDate)‘)

LET vDate=Date($(Date),‘YYYY-MM-DD‘);

TRACE <<<<< DATE COLUMN=$(DateField) ----Split: Counter=$(counter) Measure=$(vSourceName) Date=$(vDate),$(Date) >>>>>;

$(vSourceName):

LOAD *;

SQL SELECT *

FROM "$(vDBName)".dbo."$(vSourceName)"

WHERE $(DateField)=‘$(vDate)‘ ;

Let nRow=NoOfRows(‘$(vSourceName)‘);

IF NoOfRows(‘$(vSourceName)‘)>0 THEN

TRACE <<<<< nRows=$(nRow)>>>>>;

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vDate).qvd(qvd);

ENDIF;

DROP TABLE $(vSourceName);

NEXT Date

NEXT counter

DROP TABLEMeasureTable;

Partial Transaction Tab:

/* Reload for today‘s data orfor a specific day */

Trace <<<<Reload Daily ABC_BI_INV_LINES/ABC_BI_INV_HEADERS From SQLServer to QVD>>>>;

LET vReloadDate=date(today()-1,‘YYYY-MM-DD‘);

//LET vReloadDate=‘2012-06-01‘;

MeasureTable:

Load

* INLINE

[Measure

ABC_BI_INV_LINES

ABC_BI_INV_HEADERS

];

FOR counter = 1 to NoOfRows(‘MeasureTable‘)

LET vSourceName=Fieldvalue(‘Measure‘, $(counter));

IF ‘$(vSourceName)‘=‘ABC_BI_INV_HEADERS‘ THEN

SET DateField=‘INVOICE_DATE‘;

ELSE

SET DateField=‘TRX_DATE‘;

ENDIF;

TRACE <<<<< Reload: Counter=$(counter) Measure=$(vSourceName) Reload Date=$(vReloadDate)>>>>>;

$(vSourceName):

LOAD *;

SQL SELECT *

FROM "$(vDBName)".dbo."$(vSourceName)"

WHERE $(DateField)=‘$(vReloadDate)‘;

Let nRow=NoOfRows(‘$(vSourceName)‘);

IF NoOfRows(‘$(vSourceName)‘)>0 THEN

TRACE <<<<< nRows=$(nRow)>>>>>;

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vReloadDate).qvd(qvd);

ENDIF;

DROP TABLE $(vSourceName);

NEXT counter;

DROP TABLEMeasureTable;

Merge Daily QVD Tab:

/* Merge 3-Year daily QVDs into1 3-year QVD */

Trace <<<<< Merge Daily QVD >>>>>;

MeasureTable:

Load

* INLINE

[Measure

ABC_BI_INV_LINES

ABC_BI_INV_HEADERS

];

FOR counter = 1 to NoOfRows(‘MeasureTable‘)

LET vSourceName=Fieldvalue(‘Measure‘, $(counter));

TRACE <<<<< Merge: Counter=$(counter) Measure=$(vSourceName) >>>>>;

Let iFile=0;

For Each File in filelist(vQvdFolder& ‘\$(vSourceName)\$(vSourceName)_*.qvd‘)

LET vFileDate=Left(right(‘$(File)‘,14),10);

TRACE <<<<< FileDate=$(vFileDate) >>>>>;

IF num(‘$(vFileDate)‘)>=num(‘$(vStartDate)‘) AND num(‘$(vFileDate)‘)<=num(‘$(vEndDate)‘) THEN

IF $(iFile)=0 THEN

TRACE <<<Replace existing QVD, iFile=0>>>;

$(vSourceName):

LOAD *

FROM $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vFileDate).qvd(qvd);

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName).qvd(qvd);

ENDIF;

IF $(iFile)=1 THEN

TRACE <<<Update existing QVD, iFile=$(iFile)>>>;

$(vSourceName):

LOAD *

FROM $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vFileDate).qvd(qvd);

Join ($(vSourceName))

LOAD *

FROM $(vQvdFolder)\$(vSourceName).qvd(qvd);

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName).qvd(qvd);

ENDIF;

LET iFile=1;

DROP TABLE $(vSourceName);

ENDIF;

NEXT File

Next counter

DROP TABLEMeasureTable;

Update Dimension Tab:

TRACE <<<<<Update Dimension Tables >>>>>;

DimTable:

Load

* INLINE

[Dimension

ABC_BI_ITEM

ABC_BI_SALESREPS

];

For counter =1 to NoOfRows(‘DimTable‘)

LET vSourceName=Fieldvalue(‘Dimension‘,$(counter));

Trace <<<<<Counter=$(counter)Update Table $(vSourceName)>>>>>;

$(vSourceName):

LOAD *;

SQL SELECT *

FROM "$(vDBName)".dbo."$(vSourceName)";

Let nRow=NoOfRows(‘$(vSourceName)‘);

IF NoOfRows(‘$(vSourceName)‘)>0THEN

TRACE<<<<< nRows=$(nRow)>>>>>;

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName).qvd(qvd);

ENDIF;

DROP TABLE $(vSourceName);

TRACE<<<<<DIMENSION TABLE UPDATED>>>>>;

Next counter

DROP TABLE DimTable;

SET DecimalSep=‘.‘;

SET MoneyThousandSep=‘,‘;

SET MoneyDecimalSep=‘.‘;

SET MoneyFormat=‘$#,##0.00;($#,##0.00)‘;

SET TimeFormat=‘h:mm:ss TT‘;

SET DateFormat=‘YYYY-MM-DD‘;

SET TimestampFormat=‘YYYY-MM-DD h:mm:ss[.fff] TT‘;

SET MonthNames=‘Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec‘;

SET DayNames=‘Mon;Tue;Wed;Thu;Fri;Sat;Sun‘;

//setvQvdFolder=‘D:\Manie\ABC\QV_REPORT\PLS\QVD‘;

set vQvdFolder=‘D:\Watson\ABC\QV_REPORT\BDS\QVD‘; //The location is on Watson‘s own PC

SET vDBName=‘DW‘;

//OLEDB CONNECT TO[Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;DataSource=192.168.2.250;Use Procedure for Prepare=1;Auto Translate=True;PacketSize=4096;Workstation ID=8BFWC02;Use Encryption for Data=False;Tag with columncollation when possible=False];

//ODBC CONNECT32 TO DW;

//OLEDB CONNECT32 TO[Provider=SQLOLEDB.1;Persist Security Info=False;User ID=abcmis;InitialCatalog=DW;Data Source=192.168.2.250;Use Procedure for Prepare=1;AutoTranslate=True;Packet Size=4096;Workstation ID=R9HDET7;Use Encryption forData=False;Tag with column
collation when possible=False];

OLEDB CONNECT32 TO [Provider=SQLOLEDB.1;Persist Security Info=False;UserID=abcmis;Initial Catalog=DW;Data Source=192.168.2.250;Use Procedure forPrepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=R9HDET7;UseEncryption for Data=False;Tag with column
collation when possible=False];

IF Month(now())>=4 THEN

LET vStartYear=Year(now())-2;

ELSE

LET vStartYear=Year(now())-3;

ENDIF;

SET vMonthDay=‘04-01‘;

LET vStartDate=Date(‘$(vStartYear)-$(vMonthDay)‘,‘YYYY-MM-DD‘);//num(Date(‘$(vStartYear)-$(vMonthDay)‘,‘YYYY-MM-DD‘));

LET vEndDate=Date(today()-1,‘YYYY-MM-DD‘);//num(today()-1);num(Date(‘2012-04-18‘,‘YYYY-MM-DD‘));

Trace <<<<<Period: From $(vStartDate) to $(vEndDate) >>>>>;

Transaction Tab:

MeasureTable:

LOAD

* INLINE

[Measure

ABC_BI_INV_LINES

ABC_BI_INV_HEADERS

];

FOR counter = 1 to NoOfRows(‘MeasureTable‘)  //FORcounter = 1 to NoOfRows(‘SourceTable‘)

LET vSourceName=Fieldvalue(‘Measure‘, $(counter));

IF ‘$(vSourceName)‘=‘ABC_BI_INV_HEADERS‘ THEN

SET DateField=‘INVOICE_DATE‘;

ELSE

SET DateField=‘TRX_DATE‘;

ENDIF;

For Date = num(‘$(vStartDate)‘) to num(‘$(vEndDate)‘)

LET vDate=Date($(Date),‘YYYY-MM-DD‘);

TRACE <<<<< DATE COLUMN=$(DateField) ----Split: Counter=$(counter) Measure=$(vSourceName) Date=$(vDate),$(Date) >>>>>;

$(vSourceName):

LOAD *;

SQL SELECT *

FROM "$(vDBName)".dbo."$(vSourceName)"

WHERE $(DateField)=‘$(vDate)‘ ;

Let nRow=NoOfRows(‘$(vSourceName)‘);

IF NoOfRows(‘$(vSourceName)‘)>0 THEN

TRACE <<<<< nRows=$(nRow)>>>>>;

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vDate).qvd(qvd);

ENDIF;

DROP TABLE $(vSourceName);

NEXT Date

NEXT counter

DROP TABLEMeasureTable;

Partial Transaction Tab:

/* Reload for today‘s data orfor a specific day */

Trace <<<<Reload Daily ABC_BI_INV_LINES/ABC_BI_INV_HEADERS From SQLServer to QVD>>>>;

LET vReloadDate=date(today()-1,‘YYYY-MM-DD‘);

//LET vReloadDate=‘2012-06-01‘;

MeasureTable:

Load

* INLINE

[Measure

ABC_BI_INV_LINES

ABC_BI_INV_HEADERS

];

FOR counter = 1 to NoOfRows(‘MeasureTable‘)

LET vSourceName=Fieldvalue(‘Measure‘, $(counter));

IF ‘$(vSourceName)‘=‘ABC_BI_INV_HEADERS‘ THEN

SET DateField=‘INVOICE_DATE‘;

ELSE

SET DateField=‘TRX_DATE‘;

ENDIF;

TRACE <<<<< Reload: Counter=$(counter) Measure=$(vSourceName) Reload Date=$(vReloadDate)>>>>>;

$(vSourceName):

LOAD *;

SQL SELECT *

FROM "$(vDBName)".dbo."$(vSourceName)"

WHERE $(DateField)=‘$(vReloadDate)‘;

Let nRow=NoOfRows(‘$(vSourceName)‘);

IF NoOfRows(‘$(vSourceName)‘)>0 THEN

TRACE <<<<< nRows=$(nRow)>>>>>;

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vReloadDate).qvd(qvd);

ENDIF;

DROP TABLE $(vSourceName);

NEXT counter;

DROP TABLEMeasureTable;

Merge Daily QVD Tab:

/* Merge 3-Year daily QVDs into1 3-year QVD */

Trace <<<<< Merge Daily QVD >>>>>;

MeasureTable:

Load

* INLINE

[Measure

ABC_BI_INV_LINES

ABC_BI_INV_HEADERS

];

FOR counter = 1 to NoOfRows(‘MeasureTable‘)

LET vSourceName=Fieldvalue(‘Measure‘, $(counter));

TRACE <<<<< Merge: Counter=$(counter) Measure=$(vSourceName) >>>>>;

Let iFile=0;

For Each File in filelist(vQvdFolder& ‘\$(vSourceName)\$(vSourceName)_*.qvd‘)

LET vFileDate=Left(right(‘$(File)‘,14),10);

TRACE <<<<< FileDate=$(vFileDate) >>>>>;

IF num(‘$(vFileDate)‘)>=num(‘$(vStartDate)‘) AND num(‘$(vFileDate)‘)<=num(‘$(vEndDate)‘) THEN

IF $(iFile)=0 THEN

TRACE <<<Replace existing QVD, iFile=0>>>;

$(vSourceName):

LOAD *

FROM $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vFileDate).qvd(qvd);

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName).qvd(qvd);

ENDIF;

IF $(iFile)=1 THEN

TRACE <<<Update existing QVD, iFile=$(iFile)>>>;

$(vSourceName):

LOAD *

FROM $(vQvdFolder)\$(vSourceName)\$(vSourceName)_$(vFileDate).qvd(qvd);

Join ($(vSourceName))

LOAD *

FROM $(vQvdFolder)\$(vSourceName).qvd(qvd);

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName).qvd(qvd);

ENDIF;

LET iFile=1;

DROP TABLE $(vSourceName);

ENDIF;

NEXT File

Next counter

DROP TABLEMeasureTable;

Update Dimension Tab:

TRACE <<<<<Update Dimension Tables >>>>>;

DimTable:

Load

* INLINE

[Dimension

ABC_BI_ITEM

ABC_BI_SALESREPS

];

For counter =1 to NoOfRows(‘DimTable‘)

LET vSourceName=Fieldvalue(‘Dimension‘,$(counter));

Trace <<<<<Counter=$(counter)Update Table $(vSourceName)>>>>>;

$(vSourceName):

LOAD *;

SQL SELECT *

FROM "$(vDBName)".dbo."$(vSourceName)";

Let nRow=NoOfRows(‘$(vSourceName)‘);

IF NoOfRows(‘$(vSourceName)‘)>0THEN

TRACE<<<<< nRows=$(nRow)>>>>>;

STORE $(vSourceName) into $(vQvdFolder)\$(vSourceName).qvd(qvd);

ENDIF;

DROP TABLE $(vSourceName);

TRACE<<<<<DIMENSION TABLE UPDATED>>>>>;

Next counter

DROP TABLEDimTable;

时间: 2024-12-19 18:41:10

QLIKVIEW如何写增量加载脚本的相关文章

无阻塞加载脚本,按序执行

通常加载页面的时候,对于组件是并行下载的,现代大部分浏览器对于Js同样也是支持并行下载,但是在脚本下载.解析并执行完毕之前,不会开始下载任何其他内容. 正常引入: 可以看出,在脚本下载完毕后的一段时间内(该时间在解析执行脚本),不会对其他组件进行下载,以下几种方案解决该问题. 1. XHR Eval加载脚本: 即使用ajax引入脚本,并通过eval对其执行. 代码: var xhrObj = getXHRObject(); xhrObj.onreadystatechange = function

【Win10 应用开发】实现数据的增量加载

今天,老周有小故事讲,国庆期间.有一次老周在某站台上候公交车.老周旁边也站满了人,突然,有一位头发弄得像电线杆的小伙子,不知为何,没有先兆地就大笑起来. 老周先是看了那小伙子一眼,他手上没有拿什么东西(一瓶水),也没在看书或手机,就这样忽然大笑不止.随即,老周便后退了两步,观察一下其他人有什么反应. 一位年轻妈妈拉着小女儿走开了,接着,一位大叔走到垃圾桶旁边拨弄烟灰:然后,一位女孩后退了一两步:站在发笑者旁边的一位先生蹲下身来,不知道在做什么…… 如果是你,你会有什么反应? ==========

第一百一十八节,JavaScript,动态加载脚本和样式

JavaScript,动态加载脚本和样式 一动态脚本 当网站需求变大,脚本的需求也逐步变大.我们就不得不引入太多的JS脚本而降低了整站的性能,所以就出现了动态脚本的概念,在适时的时候加载相应的脚本. 比如:我们想在需要检测浏览器的时候,再引入检测文件. 1动态加载js文件 window.onload = function() { //window.onload事件,等待html执行完成后,执行匿名函数 //判断要加载的文件是否加载成功 alert(typeof BrowserDetect); }

无阻塞加载脚本

一个页面,从被请求访问,到用户可以看到页面.操作页面,到最后页面完全加载完毕,中间需要经历一个相当奇幻的过程,这个过程的速度被"web性能师"孜孜不倦.前赴后继的优化.本文讨论的是其中一个优化. 浏览器线程和阻塞 虽然大家耳熟能详的一句话是: JavaScript是单线程的. 但是: 浏览器当然不是单线程的. 浏览器的多线程中,有的线程负责加载资源,有的线程负责执行脚本,有的线程负责渲染界面,有的线程负责轮询.监听用户事件. 这些线程,根据浏览器自身特点以及web标准等等,有的会被浏览

js动态加载脚本

首先我们需要一个被加载的js文件,我在一个固定文件夹下创建了一个package.js,打开后在里面写一个方法functionOne,很简单,代码如下: [javascript] view plain copy function functionOne(){ alert("成功加载"); } 后面的html文件都创建在同一个目录下. 方法一:直接document.write 在同一个文件夹下面创建一个function1.html,代码如下: [html] view plain copy

js实现动态加载脚本的方法实例汇总

本文实例讲述了js实现动态加载脚本的方法.分享给大家供大家参考,具体如下: 最近公司的前端地图产品需要做一下模块划分,希望用户用到哪一块的功能再加载哪一块的模块,这样可以提高用户体验. 所以到处查资料研究js动态脚本的加载,不过真让人伤心啊!,网上几乎都是同一篇文章,4种方法,讨厌其中拷贝别人成果的人,也不加个原文的链接.哎!关键是最后一种方法还有点错误.经过两天的研究查阅资料,在这里和大家分享一下. 首先我们需要一个被加载的js文件,我在一个固定文件夹下创建了一个package.js,打开后在

LABjs学习(一)之无阻塞动态并行加载脚本文件以及管理执行顺序

什么是LABjs LABjs是一个动态的脚本加载器,LABjs的定义特性是能够在浏览器允许的范围内以最快的速度并行加载所有JavaScript文件,但是如果文件之间存在依赖关系,则可以选择确保正确的执行顺序. 总计来说就是:动态并行加载脚本文件以及管理加载脚本文件的执行顺序 使用方法 $LAB对象替代了<script>标签,然后.script()方法表示加载Javascript文件,不带参数的.wait()方法表示立即运行刚才加载的Javascript文件,带参数的.wait()方法也是立即运

无阻塞加载脚本的方案

1.动态加载脚本 <script type="text/javascript"> function loadScript(url){ var script=document.createElement("script"); script.type="text/javascript"; script.src=url; document.body.appendChild(script); } loadScript("js/sid

跨域加载脚本或页面获取内容

$.extend({     /**     * 跨域装载JS脚本,获取页面窗口对象,从而获得DOM内容     * @param string url 需要读取的脚本地址     * @param function callback 回调函数,参数为载入后的窗口win对象     * @param string charset 指定字符编码     */     'crossGetScript':function(url,callback,charset){