<?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: Variable to use in a query in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517200#M105893</link>
    <description>&lt;P&gt;Injecting values into your sql statement is actually very easy and can lead you to all kinds of dynamic sql statements. The case you mentioned would look something like below.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//set the value of your variable
Let vWhereDate = Date(GetDate() - IF( WeekDay(Today()) = 'Sat'),1000,365));

//Insert the value into your sql statement
SQL Select * 
from SALES 
where Sale_Date &amp;lt; '$(vWhereDate)';&lt;/LI-CODE&gt;&lt;P&gt;The key to the whole thing is to set the variable so it gives you the value you want in the query. In this case instead of calculating part of it in the where clause i did it in the variable expression. the Dollar Sign expansion in the sql statement inserts the value of the variable into your sql statement.&lt;/P&gt;</description>
    <pubDate>Thu, 08 May 2025 21:16:20 GMT</pubDate>
    <dc:creator>chriscammers</dc:creator>
    <dc:date>2025-05-08T21:16:20Z</dc:date>
    <item>
      <title>Variable to use in a query</title>
      <link>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517185#M105886</link>
      <description>&lt;P&gt;I have a SQL created like below. I am trying to get a variable to use in the SQL. Can you check this would work?&lt;/P&gt;&lt;P&gt;variable V = IF( WeekDay(Today()) = 'Sat') Then 1000 else 365&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Select&amp;nbsp; * from SALES&lt;/P&gt;&lt;P&gt;where sale_date &amp;lt; sysdate() - V&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 18:57:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517185#M105886</guid>
      <dc:creator>jjustingkm</dc:creator>
      <dc:date>2025-05-08T18:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Variable to use in a query</title>
      <link>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517200#M105893</link>
      <description>&lt;P&gt;Injecting values into your sql statement is actually very easy and can lead you to all kinds of dynamic sql statements. The case you mentioned would look something like below.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//set the value of your variable
Let vWhereDate = Date(GetDate() - IF( WeekDay(Today()) = 'Sat'),1000,365));

//Insert the value into your sql statement
SQL Select * 
from SALES 
where Sale_Date &amp;lt; '$(vWhereDate)';&lt;/LI-CODE&gt;&lt;P&gt;The key to the whole thing is to set the variable so it gives you the value you want in the query. In this case instead of calculating part of it in the where clause i did it in the variable expression. the Dollar Sign expansion in the sql statement inserts the value of the variable into your sql statement.&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 21:16:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517200#M105893</guid>
      <dc:creator>chriscammers</dc:creator>
      <dc:date>2025-05-08T21:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Variable to use in a query</title>
      <link>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517211#M105898</link>
      <description>&lt;P&gt;I don't think GetDate() is Qlik function. Perhaps we can try like below&lt;/P&gt;&lt;P&gt;Let V = Date(Today()-IF( WeekDay(Today()) = 'Fri', 1000, 365));&lt;BR /&gt;Trace '$(V)';&lt;/P&gt;&lt;P&gt;Select&amp;nbsp; * from SALES where sale_date &amp;lt; '$(V)';&lt;/P&gt;&lt;P&gt;Make sure date format in aligned for both sale_date and variable.&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 02:42:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Variable-to-use-in-a-query/m-p/2517211#M105898</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2025-05-09T02:42:53Z</dc:date>
    </item>
  </channel>
</rss>

