<?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 Re: Converting a SQL code to something useful in Qlikview script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697407#M667265</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;*,&lt;/P&gt;&lt;P&gt;MonthStart(Today(), -18)&amp;nbsp; AS Month; &lt;/P&gt;&lt;P&gt;LOAD&amp;nbsp; &lt;/P&gt;&lt;P&gt;log_opportunityid,&amp;nbsp; &lt;/P&gt;&lt;P&gt;max(createdon) AS CreatedOn&lt;/P&gt;&lt;P&gt;from QVDFileName.qvd&lt;/P&gt;&lt;P&gt;where createdon &amp;lt; MonthStart(Today(), -17)&amp;nbsp; &lt;/P&gt;&lt;P&gt;group by log_opportunityid ; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jagan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 27 Oct 2014 04:23:01 GMT</pubDate>
    <dc:creator>jagan</dc:creator>
    <dc:date>2014-10-27T04:23:01Z</dc:date>
    <item>
      <title>Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697405#M667263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a code that pull data from SQL, and I need to convert it to something that will work in qlikview script. Here is the SQL code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14143563243292415" jivemacro_uid="_14143563243292415" modifiedtitle="true"&gt;
&lt;P&gt;M18 as&lt;/P&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;select distinct log_opportunityid,&lt;/P&gt;
&lt;P&gt;createdon = max(createdon),&lt;/P&gt;
&lt;P&gt;month = dateadd(m,datediff(m,0,dateadd(m,-18,getdate())),0)&lt;/P&gt;
&lt;P&gt;from [dbo].[Filteredlog_salesstagetracking] as t1&lt;/P&gt;
&lt;P&gt;where createdon &amp;lt; dateadd(m,datediff(m,0,dateadd(m,-17,getdate())),0)&lt;/P&gt;
&lt;P&gt;group by log_opportunityid&lt;/P&gt;
&lt;P&gt;),&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And this is what I have managed so far, but there's some stuff missing, like the mac(t1.createdon) stuff.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14143563241526506" jivemacro_uid="_14143563241526506"&gt;
&lt;P&gt;M18:&lt;/P&gt;
&lt;P&gt;LOAD&lt;/P&gt;
&lt;P&gt;&amp;nbsp; log_opportunityid,&lt;/P&gt;
&lt;P&gt;// Max(createdon) as createdon,&amp;nbsp;&amp;nbsp; //Error when this code is active...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Num(MonthStart(addmonths(today(),-18))) as Month&lt;/P&gt;
&lt;P&gt;FROM [..............Filteredlog.qvd] (qvd)&lt;/P&gt;
&lt;P&gt;Where createdon &amp;lt; MonthStart(Addmonths(today(),-17));&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Espen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 26 Oct 2014 20:45:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697405#M667263</guid>
      <dc:creator />
      <dc:date>2014-10-26T20:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697406#M667264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;with max (and other aggregation) you need to group by (as in SQL)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;I also added a Max to MonthStart&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;M18:&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;LOAD&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log_opportunityid,&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Max(createdon) as createdon,&amp;nbsp;&amp;nbsp; //Error when this code is active...&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt; font-style: inherit; font-weight: inherit; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Max(Num(MonthStart(addmonths(today(),-&lt;/SPAN&gt;&lt;SPAN class="number" style="font-style: inherit; font-weight: inherit; line-height: 1.5em; color: green; font-size: 9pt !important;"&gt;18&lt;/SPAN&gt;&lt;SPAN style="color: black; font-style: inherit; font-weight: inherit; line-height: 1.5em; font-size: 9pt !important;"&gt;)))) as Month&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;FROM [..............Filteredlog.qvd] (qvd)&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;Where createdon &amp;lt; MonthStart(Addmonths(today(),-&lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; font-size: 9pt !important; background-color: inherit;"&gt;17&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;))&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;group by &lt;SPAN style="color: #000000; font-size: 11.8181819915771px;"&gt;log_opportunityid&lt;/SPAN&gt;;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 26 Oct 2014 21:47:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697406#M667264</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2014-10-26T21:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697407#M667265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;*,&lt;/P&gt;&lt;P&gt;MonthStart(Today(), -18)&amp;nbsp; AS Month; &lt;/P&gt;&lt;P&gt;LOAD&amp;nbsp; &lt;/P&gt;&lt;P&gt;log_opportunityid,&amp;nbsp; &lt;/P&gt;&lt;P&gt;max(createdon) AS CreatedOn&lt;/P&gt;&lt;P&gt;from QVDFileName.qvd&lt;/P&gt;&lt;P&gt;where createdon &amp;lt; MonthStart(Today(), -17)&amp;nbsp; &lt;/P&gt;&lt;P&gt;group by log_opportunityid ; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jagan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 04:23:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697407#M667265</guid>
      <dc:creator>jagan</dc:creator>
      <dc:date>2014-10-27T04:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697408#M667266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jagan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems to be very close to working. But I run this in a loop where I go from 24 months back in time and up til today. And it seems like the code errors after six months in the loop, i wonder if it has to do with the createdon date not matching the criterias in the loop, but i'm not sure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attached a picture from the debug:&lt;IMG alt="error loop.jpg" class="jive-image" src="/legacyfs/online/69731_error loop.jpg" style="width: 620px; height: 349px;" /&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Espen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 10:44:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697408#M667266</guid>
      <dc:creator />
      <dc:date>2014-10-27T10:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697409#M667267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you are missing a group by statement which is required for aggregation depending on other fields. in your case you need: where createdon &amp;lt; MonthStart(Today(), -17) group by log_opportunityid ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just as Jagan posted it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 20:43:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697409#M667267</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-10-27T20:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697410#M667268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You missed &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;group by log_opportunityid&amp;nbsp; in your statement.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jagan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Oct 2014 02:31:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697410#M667268</guid>
      <dc:creator>jagan</dc:creator>
      <dc:date>2014-10-28T02:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SQL code to something useful in Qlikview script</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697411#M667269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, i didn't noticie that i had forgotten to group them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Espen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Oct 2014 08:24:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-a-SQL-code-to-something-useful-in-Qlikview-script/m-p/697411#M667269</guid>
      <dc:creator />
      <dc:date>2014-10-28T08:24:39Z</dc:date>
    </item>
  </channel>
</rss>

