<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SQL WHERE clause based on loaded data in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206245#M62438</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you are almost there. You need a couple of extra steps:&lt;/P&gt;&lt;P&gt;1. Load from QVD&lt;/P&gt;&lt;P&gt;2. Calculate max(Date) using resident load and group by&lt;/P&gt;&lt;P&gt;3. Use function peek() to assign the value to a variable vMaxDate&lt;/P&gt;&lt;P&gt;4. Use $-sign expansion to pass the value to SQL:&lt;/P&gt;&lt;P&gt;WHERE calendardate &amp;gt; $(vMaxDate)&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Oct 2009 23:11:57 GMT</pubDate>
    <dc:creator>Oleg_Troyansky</dc:creator>
    <dc:date>2009-10-02T23:11:57Z</dc:date>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206244#M62437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm not sure if this is possible in QlikView, but am hoping it is. I am loading a qvd file, then loading the latest data from SQL, finally storing the data back to the qvd file ready for the next day.&lt;/P&gt;&lt;P&gt;At the moment I load one day's data on each load. However if the QlikView file is not ran that day, the day is missing, and if it gets ran twice then the day is duplicated.&lt;/P&gt;&lt;P&gt;What I need is something like this:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DataTable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD CalendarDate, FileSize&lt;BR /&gt;FROM C:\File.QVD (qvd);&lt;/P&gt;&lt;P&gt;CONCATENATE SQL SELECT CalendarDate, FileSize&lt;BR /&gt;FROM DW.dbo.vwFileSizes&lt;BR /&gt;WHERE calendardate &amp;gt; #$(max(CalendarDate))#;&lt;/P&gt;&lt;P&gt;STORE DataTable INTO C:\File.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The bit that does not work is the #$(max(CalendarDate))# bit. I want this to be the maximum date from the qvd load.&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 22:21:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206244#M62437</guid>
      <dc:creator />
      <dc:date>2009-10-02T22:21:27Z</dc:date>
    </item>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206245#M62438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you are almost there. You need a couple of extra steps:&lt;/P&gt;&lt;P&gt;1. Load from QVD&lt;/P&gt;&lt;P&gt;2. Calculate max(Date) using resident load and group by&lt;/P&gt;&lt;P&gt;3. Use function peek() to assign the value to a variable vMaxDate&lt;/P&gt;&lt;P&gt;4. Use $-sign expansion to pass the value to SQL:&lt;/P&gt;&lt;P&gt;WHERE calendardate &amp;gt; $(vMaxDate)&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 23:11:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206245#M62438</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2009-10-02T23:11:57Z</dc:date>
    </item>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206246#M62439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll point out a potential pitfall - you might easily have a new file with the same date as a file already in the QVD. For example, you create a file, run the reload, create another file, and rerun the reload. You need to pick up the new file, not skip it just because it has the same date. To solve it, I would want to grab the max date records from the database instead of from the QVD. It's not as simple as just using "&amp;gt;=" of course, because that will double up on the max date records. How I would solve it depends on how much data you're expecting, though.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 23:22:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206246#M62439</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2009-10-02T23:22:37Z</dc:date>
    </item>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206247#M62440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply Oleg. It looks better, but is still not right. Below is the code I now have.&lt;/P&gt;&lt;P&gt;When I run this I get an error, the vMaxDate passes through "peek(MDate,0,DataTable2)", rather than the actual date.&lt;/P&gt;&lt;P&gt;Once this works the current table is DataTable2, how do I concatenate the new data to DataTable?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P style="font-style: italic"&gt;&lt;/P&gt;&lt;P style="font-style: italic"&gt;DataTable:&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;LOAD&lt;/P&gt;&lt;P&gt;&lt;/P&gt;CalendarDate &lt;P&gt;,&lt;/P&gt;&lt;P&gt;FileSize&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;FROM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;C:\File.QVD (qvd) &lt;P&gt;;&lt;/P&gt;&lt;I&gt;&lt;/I&gt;&lt;P style="font-style: italic"&gt;DataTable2:&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;load&lt;/P&gt;&lt;P&gt;&lt;/P&gt;max(CalendarDate) &lt;B&gt;as&lt;/B&gt; MDate &lt;B&gt;resident&lt;/B&gt; &lt;P&gt;DataTable;&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;set&lt;/P&gt;&lt;P&gt;&lt;/P&gt;vMaxDate=peek(MDate,0,DataTable2) &lt;P&gt;;&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;concatenate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;B&gt;SQL&lt;/B&gt; &lt;B&gt;SELECT&lt;/B&gt; CalendarDate, &lt;P&gt;FileSize&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;FROM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DW.dbo.vwFileSizes&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;calendardate &amp;gt; &lt;B&gt;&lt;I&gt;$(vMaxDate)&lt;/I&gt;&lt;/B&gt; &lt;P&gt;;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 23:51:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206247#M62440</guid>
      <dc:creator />
      <dc:date>2009-10-02T23:51:15Z</dc:date>
    </item>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206248#M62441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not certain, but I THINK you need to use LET instead of SET, and I think you need single quotes around MDate:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;LET vMaxDate=peek('MDate');&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Oct 2009 00:32:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206248#M62441</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2009-10-03T00:32:52Z</dc:date>
    </item>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206249#M62442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can get a working example of a date based incremental load from the QV Cookbook at:&lt;/P&gt;&lt;P&gt;&lt;A href="http://robwunderlich.com/Download.html"&gt;http://robwunderlich.com/Download.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The specific example is titled "Incremental reload template and example."&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Oct 2009 06:57:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206249#M62442</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2009-10-03T06:57:35Z</dc:date>
    </item>
    <item>
      <title>SQL WHERE clause based on loaded data</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206250#M62443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks John,&lt;/P&gt;&lt;P&gt;It's all working now. I've added the code below in case anyone else has the same issue. This also shows how to concatenate to an existing table other than the current table in use.&lt;/P&gt;&lt;P&gt;Thanks for all your help.&lt;/P&gt;&lt;P style="font-style: italic"&gt;DataTable:&lt;/P&gt;&lt;P&gt;&lt;B&gt;LOAD&lt;/B&gt; CalendarDate,&lt;/P&gt;&lt;P&gt;FileSize&lt;/P&gt;&lt;P&gt;&lt;B&gt;FROM&lt;/B&gt; C:\File.QVD (qvd);&lt;/P&gt;&lt;P style="font-style: italic"&gt;DataTable2:&lt;/P&gt;&lt;P&gt;&lt;B&gt;load&lt;/B&gt; max(CalendarDate) &lt;B&gt;as&lt;/B&gt; MDate &lt;B&gt;resident&lt;/B&gt; DataTable;&lt;/P&gt;&lt;P&gt;&lt;B&gt;let&lt;/B&gt; vMaxDate=peek('MDate');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;concatenate&lt;/B&gt; (DataTable) &lt;B&gt;SQL&lt;/B&gt; &lt;B&gt;SELECT&lt;/B&gt; CalendarDate, FileSize&lt;/P&gt;&lt;P&gt;&lt;B&gt;FROM&lt;/B&gt; DW.dbo.vwFileSizes&lt;/P&gt;&lt;P&gt;where calendardate &amp;gt; &lt;B&gt;&lt;I&gt;$(vMaxDate)&lt;/I&gt;&lt;/B&gt;;&lt;/P&gt;&lt;P&gt;&lt;B&gt;drop&lt;/B&gt; &lt;B&gt;table&lt;/B&gt; &lt;I&gt;DataTable2;&lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Oct 2009 16:47:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-WHERE-clause-based-on-loaded-data/m-p/206250#M62443</guid>
      <dc:creator />
      <dc:date>2009-10-05T16:47:32Z</dc:date>
    </item>
  </channel>
</rss>

