<?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>Question Re: where condition as variable (sql statement) in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832530#M4863373</link>
    <description>&lt;P&gt;Thank you very much for the reply.&lt;/P&gt;
&lt;P&gt;The approach with condition_type is SUPER! It serves exactly the need of my case.&lt;/P&gt;
&lt;P&gt;This is why I like to ask questions in this forum..&lt;/P&gt;</description>
    <pubDate>Fri, 30 Sep 2022 06:45:07 GMT</pubDate>
    <dc:creator>Baron</dc:creator>
    <dc:date>2022-09-30T06:45:07Z</dc:date>
    <item>
      <title>where condition as variable (sql statement)</title>
      <link>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaq-p/13832528</link>
      <description>&lt;P&gt;Is there a way to have a dynamic where condition in a sql statement (without the need to EXECUTE IMMEDIATE)?&lt;/P&gt;
&lt;PRE&gt;begin
declare where_stmt varchar(100);
set where_stmt = ' salary &amp;gt; 100';
select * from employees where where_stmt;
end;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 05:28:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaq-p/13832528</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2022-09-30T05:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: where condition as variable (sql statement)</title>
      <link>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832529#M4863372</link>
      <description>&lt;P&gt;You can vary particular values via connection-level variables. In V17, you can also vary table and column names via &lt;A href="https://dcx.sap.com/index.html#sqla170/en/html/ce224c029e8c482c9fb637f5df3d43e4.html*loioce224c029e8c482c9fb637f5df3d43e4"&gt;indirect identifiers&lt;/A&gt;. But to vary complete conditions including their operators (say, "salary &amp;gt; 100" vs. "salary in (100, 200, 300)" or the like), I guess you will have to use dynamic SQL. &lt;/P&gt;
&lt;P&gt;For a small and fixed choice of conditions, you could of course use some kind of "condition type variable" that would allow to choose between several predefined condition branches, such as&lt;/P&gt;
&lt;PRE&gt;   where (condition_type = 1 and salary &amp;gt; myVarValue)
      or (condition_type = 2 and salary &amp;lt; myVarValue)
      or (condition_type = 3 and SomeOtherColumn = myVarValue...)
&lt;/PRE&gt;

&lt;P&gt;probably with the need to cast your values to fitting types...&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 06:31:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832529#M4863372</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2022-09-30T06:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: where condition as variable (sql statement)</title>
      <link>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832530#M4863373</link>
      <description>&lt;P&gt;Thank you very much for the reply.&lt;/P&gt;
&lt;P&gt;The approach with condition_type is SUPER! It serves exactly the need of my case.&lt;/P&gt;
&lt;P&gt;This is why I like to ask questions in this forum..&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 06:45:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832530#M4863373</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2022-09-30T06:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: where condition as variable (sql statement)</title>
      <link>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832531#M4863374</link>
      <description>&lt;P&gt;I have one more question regarding indirect identifiers:&lt;/P&gt;
&lt;P&gt;According to the documentation, should this block work, but on SQL Anywhere 17 it doesn't:&lt;/P&gt;
&lt;PRE&gt;create or replace table dba.mytable (sn int, loc varchar(10));
CREATE OR REPLACE VARIABLE t_owner LONG VARCHAR = 'dba';
CREATE OR REPLACE VARIABLE t_name LONG VARCHAR = 'mytable';
SELECT * FROM '[t_owner]'.'[t_name]';

&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Oct 2022 10:21:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832531#M4863374</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2022-10-04T10:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: where condition as variable (sql statement)</title>
      <link>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832532#M4863375</link>
      <description>&lt;P&gt;See the comment by Jack Schueler with the corrected samples on the linked doc page (or the newer SAL Portal Help), you need &lt;STRONG&gt;back quotes&lt;/STRONG&gt; for the references:&lt;/P&gt;
&lt;PRE&gt;CREATE OR REPLACE VARIABLE t_owner LONG VARCHAR = 'GROUPO';
CREATE OR REPLACE VARIABLE t_name LONG VARCHAR = 'Employees';
SELECT * FROM `[t_owner]`.`[t_name]`;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Oct 2022 11:06:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/where-condition-as-variable-sql-statement/qaa-p/13832532#M4863375</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2022-10-04T11:06:17Z</dc:date>
    </item>
  </channel>
</rss>

