<?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 How to use calculated value in SQL statement in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825632#M1047419</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 want to fetch data from a database starting from the beginning of the current year. For this, I stored the following the following outcome of a function in a variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158809775428093" jivemacro_uid="_14158809775428093"&gt;
&lt;P&gt;LET BeginOfYear = Date#(YearStart(Today()), 'D-M-Y');&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My query is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158810519585733" jivemacro_uid="_14158810519585733"&gt;
&lt;P&gt;SQL SELECT *&lt;/P&gt;
&lt;P&gt;FROM GTISMVREPL.dbo."JOBCALL_ABNAMRO" WHERE JOBCALL_JOB_DATE &amp;gt; $(BeginOfYear);&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, when reloading, I discovered that the data fetched is far more than needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I build up the query where I manually enter the date like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158812484174660" jivemacro_uid="_14158812484174660"&gt;
&lt;P&gt;SQL SELECT *&lt;/P&gt;
&lt;P&gt;FROM GTISMVREPL.dbo."JOBCALL_ABNAMRO" WHERE JOBCALL_JOB_DATE &amp;gt; '1-1-2014';&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The right amount of data is fetched. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;How can I calculate the beginning of the current year and use that in my query/queries?&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Nov 2014 12:22:33 GMT</pubDate>
    <dc:creator />
    <dc:date>2014-11-13T12:22:33Z</dc:date>
    <item>
      <title>How to use calculated value in SQL statement</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825632#M1047419</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 want to fetch data from a database starting from the beginning of the current year. For this, I stored the following the following outcome of a function in a variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158809775428093" jivemacro_uid="_14158809775428093"&gt;
&lt;P&gt;LET BeginOfYear = Date#(YearStart(Today()), 'D-M-Y');&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My query is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158810519585733" jivemacro_uid="_14158810519585733"&gt;
&lt;P&gt;SQL SELECT *&lt;/P&gt;
&lt;P&gt;FROM GTISMVREPL.dbo."JOBCALL_ABNAMRO" WHERE JOBCALL_JOB_DATE &amp;gt; $(BeginOfYear);&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, when reloading, I discovered that the data fetched is far more than needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I build up the query where I manually enter the date like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158812484174660" jivemacro_uid="_14158812484174660"&gt;
&lt;P&gt;SQL SELECT *&lt;/P&gt;
&lt;P&gt;FROM GTISMVREPL.dbo."JOBCALL_ABNAMRO" WHERE JOBCALL_JOB_DATE &amp;gt; '1-1-2014';&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The right amount of data is fetched. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;How can I calculate the beginning of the current year and use that in my query/queries?&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 12:22:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825632#M1047419</guid>
      <dc:creator />
      <dc:date>2014-11-13T12:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use calculated value in SQL statement</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825633#M1047420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Add quotes around variable &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;BeginOfYear&lt;/SPAN&gt;&lt;/P&gt;&lt;OL class="dp-c" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; list-style-position: initial; list-style-image: initial; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;SQL SELECT *&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;FROM GTISMVREPL.dbo."JOBCALL_ABNAMRO" WHERE JOBCALL_JOB_DATE &amp;gt; '$(BeginOfYear)'; &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;BR /&gt;&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;EDIT: Use Date&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL class="dp-c" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; list-style-position: initial; list-style-image: initial; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;LET BeginOfYear = Date(YearStart(Today()), 'D-M-Y');&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 12:30:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825633#M1047420</guid>
      <dc:creator>anbu1984</dc:creator>
      <dc:date>2014-11-13T12:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use calculated value in SQL statement</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825634#M1047421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, this worked.&lt;BR /&gt;Can you explain why I need to use Date, rather than Date#?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 13:00:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825634#M1047421</guid>
      <dc:creator />
      <dc:date>2014-11-13T13:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use calculated value in SQL statement</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825635#M1047422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Date() - Convert Date to String&lt;/P&gt;&lt;P&gt;Date#() - Convert String to Date&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result of YearStart(Today()) is Date. If you want to change the format of date, then you have to use Date()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your input is string and you want to convert to date, then use Date#() -- Date#('1-1-2014', 'D-M-Y')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 13:05:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-use-calculated-value-in-SQL-statement/m-p/825635#M1047422</guid>
      <dc:creator>anbu1984</dc:creator>
      <dc:date>2014-11-13T13:05:51Z</dc:date>
    </item>
  </channel>
</rss>

