<?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: Load script variables in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478609#M1145143</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, it is possible. If the field Year in the DB is an integer, you can write:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Set vYear = 2009 ;&lt;/P&gt;&lt;P&gt;SQL SELECT * FROM Orders WHERE Year = $(vYear) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case, your fiscal years seem to have a different format, so the where clause would probably need to be a string comparison:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let vFiscalYear = &amp;lt; proper definition&amp;gt; ;&lt;/P&gt;&lt;P&gt;SQL SELECT * FROM Orders WHERE FiscalYear = '$(vFiscalYear)' ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Aug 2013 07:23:39 GMT</pubDate>
    <dc:creator>hic</dc:creator>
    <dc:date>2013-08-09T07:23:39Z</dc:date>
    <item>
      <title>Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478608#M1145142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible to use variables in the load script to then use in the where clause to limit data loaded into Qlikview?&amp;nbsp; &lt;/P&gt;&lt;P&gt;Depending on the current date I would like to create a variable that is used in the SQL select statement to determine what data gets loaded.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example in SQL Server 2012 I can write:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DECLARE @fiscalyear varchar(30)&lt;/P&gt;&lt;P&gt;DECLARE @lastfiscalyear varchar(30)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF GETDATE()&amp;gt;=CAST(CONVERT(VARCHAR(10),'07/01/' + DATENAME(YEAR,GETDATE())) as DATE)&lt;/P&gt;&lt;P&gt;BEGIN&lt;/P&gt;&lt;P&gt;SET @fiscalyear = SUBSTRING(DATENAME(YEAR,GETDATE()),3,2) + SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,1,GETDATE())),3,2) + '&amp;nbsp; Fiscal Year'&lt;/P&gt;&lt;P&gt;SET @lastfiscalyear = SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-1,GETDATE())),3,2) + SUBSTRING(DATENAME(YEAR,GETDATE()),3,2) + '&amp;nbsp; Fiscal Year' &lt;/P&gt;&lt;P&gt;END&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;BEGIN&lt;/P&gt;&lt;P&gt;SET @fiscalyear = SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-1,GETDATE())),3,2) + SUBSTRING(DATENAME(YEAR,GETDATE()),3,2) + '&amp;nbsp; Fiscal Year'&lt;/P&gt;&lt;P&gt;SET @lastfiscalyear = SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-2,GETDATE())),3,2) + SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-1,GETDATE())),3,2) +&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp; Fiscal Year'&lt;/P&gt;&lt;P&gt;END&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then have my SQL Statement here using @fiscalyear and @lastfiscalyear in my where clause, but I can't seem to figure out how this would work in the Qlikview load script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 17:29:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478608#M1145142</guid>
      <dc:creator />
      <dc:date>2013-08-08T17:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478609#M1145143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, it is possible. If the field Year in the DB is an integer, you can write:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Set vYear = 2009 ;&lt;/P&gt;&lt;P&gt;SQL SELECT * FROM Orders WHERE Year = $(vYear) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case, your fiscal years seem to have a different format, so the where clause would probably need to be a string comparison:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let vFiscalYear = &amp;lt; proper definition&amp;gt; ;&lt;/P&gt;&lt;P&gt;SQL SELECT * FROM Orders WHERE FiscalYear = '$(vFiscalYear)' ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 07:23:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478609#M1145143</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2013-08-09T07:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478610#M1145144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, I've worked my way through all the errors this was throwing me and I'm still stuck.&amp;nbsp; As Henric has mentioned I changed the code a little, but I still get an error saying:&amp;nbsp; "Invalid column name 'vlastfiscalyear'"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I have so far:&lt;/P&gt;&lt;P&gt;IF Today()&amp;gt;=Date('07/01/' + Date(Today(),'YYYY'),'YYYY-MM-DD') THEN&lt;/P&gt;&lt;P&gt;LET vfiscalyear = Mid(Date(Today(),'YYYY'),3,2) + Mid(Date(AddYears(Today(),1),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P&gt;LET vlastfiscalyear = Mid(Date(AddYears(Today(),-1),'YYYY'),3,2) + Mid(Date(Today(),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;LET vfiscalyear = Mid(Date(AddYears(Today(),-1),'YYYY'),3,2) + Mid(Date(Today(),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P&gt;LET vlastfiscalyear = Mid(Date(AddYears(Today(),-2),'YYYY'),3,2) + Mid(Date(AddYears(Today(),-1),'YYYY'),3,2) +&amp;nbsp;&amp;nbsp;&amp;nbsp; '&amp;nbsp; Fiscal Year' ;&lt;/P&gt;&lt;P&gt;ENDIF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I change the 'v' to '@' like SQL Server I get the error "Must declare the scalar variable "@lastfiscalyear" and I'm sure once it gets past this one it will require it for the next.&amp;nbsp; How would I declare the variables or get the 'v' to work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 14:29:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478610#M1145144</guid>
      <dc:creator />
      <dc:date>2013-08-09T14:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478611#M1145145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That error shows that the SQL Server interprets the variable as a DB field, which it shouldn't. Check that you use single quotes around the variable expansion (or no quotes, if it is a number).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should NOT change the 'v' to a &lt;A href="mailto:'@'"&gt;'@'&lt;/A&gt; - it is not a SQL variable. It is a QlikView variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Run the script in the debugger, and you should see something like the image below:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Execute step-wise (red)&lt;/LI&gt;&lt;LI&gt;Check that the script looks OK (green). This is what QlikView sees.&lt;/LI&gt;&lt;LI&gt;Check that the variable expansion has been made correctly (blue). This is what is sent to the SQL Server.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="45221" class="jive-image-thumbnail jive-image" onclick="" alt="Debugger.png" src="https://community.qlik.com/legacyfs/online/45221_Debugger.png" width="450" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 14:43:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478611#M1145145</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2013-08-09T14:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478612#M1145146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Henric this helped, in that it set the variables and now my script passes to the SQL Server, but I'm still running into the issue where it won't calculate my variables.&amp;nbsp; For example as I step through the script the variable ends up being "&lt;SPAN style="color: #737373; font-family: Arial; background-color: #ffffff;"&gt;Mid(Date(Today(),'YYYY'),3,2) + Mid(Date(AddYears(Today(),1),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year'"&lt;/SPAN&gt; instead of "1213&amp;nbsp; Fiscal Year".&amp;nbsp; How do I get it to calculate the variable correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 15:03:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478612#M1145146</guid>
      <dc:creator />
      <dc:date>2013-08-09T15:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478613#M1145147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure, but it could be that you use + as string concatenation operator. This does not work. Use &amp;amp; instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further, maybe some date handling could be made simper. For instance you use&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #737373; font-family: Arial; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Today()&amp;gt;=Date('07/01/' + Date(Today(),'YYYY'),'YYYY-MM-DD') &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;when you perhaps should use &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #737373; font-family: Arial; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;Today()&amp;gt;=MakeDate(Year(Today()),01,07)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #737373; font-family: Arial; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mid(Date(Today(),'YYYY'),3,2) + Mid(Date(AddYears(Today(),1),'YYYY'),3,2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;can be replaced with&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #737373; font-family: Arial; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date(Today(),'YY') &amp;amp; Date(AddYears(Today(),1),'YY')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 15:20:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478613#M1145147</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2013-08-09T15:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Load script variables</title>
      <link>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478614#M1145148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Henric for all your help.&amp;nbsp; I finally go it to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once I finally realized what it was doing, it came together.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I realized is that Qlikview wasn't calculating the variable and then putting it in the SQL code to then pass to SQL Server, it was just passing the exact syntax that was in the variable and was expecting SQL Server to calculate, so I changed the variables as if I was to write them in SQL Server.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;This:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;IF Today()&amp;gt;=Date('07/01/' + Date(Today(),'YYYY'),'YYYY-MM-DD') THEN&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vfiscalyear = Mid(Date(Today(),'YYYY'),3,2) + Mid(Date(AddYears(Today(),1),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vlastfiscalyear = Mid(Date(AddYears(Today(),-1),'YYYY'),3,2) + Mid(Date(Today(),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;ELSE&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vfiscalyear = Mid(Date(AddYears(Today(),-1),'YYYY'),3,2) + Mid(Date(Today(),'YYYY'),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vlastfiscalyear = Mid(Date(AddYears(Today(),-2),'YYYY'),3,2) + Mid(Date(AddYears(Today(),-1),'YYYY'),3,2) +&amp;nbsp;&amp;nbsp;&amp;nbsp; '&amp;nbsp; Fiscal Year' ;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;ENDIF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Should be this:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;IF Today()&amp;gt;=Date('07/01/' + Date(Today(),'YYYY'),'YYYY-MM-DD') THEN&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vfiscalyear = SUBSTRING(DATENAME(YEAR,GETDATE()),3,2) + SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,1,GETDATE())),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vlastfiscalyear = SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-1,GETDATE())),3,2) + SUBSTRING(DATENAME(YEAR,GETDATE()),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;ELSE&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vfiscalyear = SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-1,GETDATE())),3,2) + SUBSTRING(DATENAME(YEAR,GETDATE()),3,2) + '&amp;nbsp; Fiscal Year';&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;LET vlastfiscalyear =&amp;nbsp; SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-2,GETDATE())),3,2) + SUBSTRING(DATENAME(YEAR,DATEADD(YEAR,-1,GETDATE())),3,2) + '&amp;nbsp; Fiscal Year' ;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;ENDIF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 15:50:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-script-variables/m-p/478614#M1145148</guid>
      <dc:creator />
      <dc:date>2013-08-09T15:50:23Z</dc:date>
    </item>
  </channel>
</rss>

