<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>We have a need to do a select query. The &amp;quot;WHERE&amp;quot; of the SQL statement</title><link>https://community.appian.com/discussions/f/general/3895/we-have-a-need-to-do-a-select-query-the-where-of-the-sql-statement</link><description>We have a need to do a select query. The &amp;quot;WHERE&amp;quot; of the SQL statement will need to be dynamic.The reason is that this is a &amp;quot;search&amp;quot; that our users are doing. They may select to search on 1 to 5 fields. In other words, the columns in our where clause will</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13671?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 01:59:36 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f0e26369-f901-4e71-9759-9e28fc74350f</guid><dc:creator>Chris</dc:creator><description>Great!  On your form or search selection, you can set whatever is entered to variables (normal text, no &amp;#39;%&amp;#39;).  Then on the ac! Data Inputs for the Query DB node, set as:&lt;br /&gt;&lt;br /&gt;=&amp;quot;%&amp;quot; &amp;amp; pv!col1Filter &amp;amp; &amp;quot;%&amp;quot;&lt;br /&gt;&lt;br /&gt;Where pv!col1Filter is the exact text you would like to filter on, surrounded by 2 &amp;quot;%&amp;quot; signs.&lt;br /&gt;&lt;br /&gt;COALESCE() takes 2 arguments and returns the first that is not null - so if the row is null, it will return whatever you enter as the second argument (basically replacing null values during the search) - or it will return the actual data.  I do use a space in &amp;#39; &amp;#39; for text data.  I have tried no space and get better results with a space.  Also, for other data types you can use convert to string, such as &amp;quot;COALESCE(to_char(Column3),&amp;#39; &amp;#39;).&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13670?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 01:21:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9f692161-51eb-4f2e-87b4-3939def624d2</guid><dc:creator>scotte</dc:creator><description>Thanks, I think this is working. We are using Oracle. Confirming: So in the Oracle sql above you are saying to make the col1Filter variable = to %  ?   Also, is that a space between the two quotes as in &amp;#39; &amp;#39;?      I&amp;#39;m trying to understand the COALESCE how it works?  And what if some of the fields we are searching on are numeric or dates types? Thanks!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13668?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 00:39:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3a37a55e-df64-4cfb-9f6c-4c46f27a9541</guid><dc:creator>Chris</dc:creator><description>Ah yes, in my use case we do not have null situations.  LIKE will not return records with null values.  To work around that, instead of &amp;quot;Column4 LIKE ac!col4Filter&amp;quot; you should be able to use:&lt;br /&gt;&lt;br /&gt;Oracle:  COALESCE(Column4, &amp;#39; &amp;#39;) LIKE ac!col1Filter &lt;br /&gt;SQL:  IsNull(Column4, &amp;#39; &amp;#39;) LIKE ac!col1Filter &lt;br /&gt;&lt;br /&gt;.. with your ac! input for col1Filter set to:  =&amp;quot;%&amp;quot; &amp;amp; pv!Col1Filter &amp;amp; &amp;quot;%&amp;quot;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13667?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 00:29:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:335cca42-c15f-44da-822d-86f92a398f1d</guid><dc:creator>scotte</dc:creator><description>Yes, that is what we thought.  But when we put in a % as a value, you only get returned records that have something in that field.  Try it yourself?  So if I have 10 records and 3 of the records Last_Name is null and WHERE  FIRST_NAME LIKE ac!acFirstName and acFirstName has a value of % I only get 7 records returned. I should get all 10?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13666?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 00:22:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:494249f5-78dd-4e9d-b9c3-6a1783b5845f</guid><dc:creator>Chris</dc:creator><description>Sorry, you will need &amp;quot;%%&amp;quot; in your inputs.  Using my SQL above, you can set your Query DB node inputs to =&amp;quot;%&amp;quot; &amp;amp; pv!Col1Filter &amp;amp; &amp;quot;%&amp;quot; - etc, and that should work for you.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13665?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 00:17:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:44751fe2-454f-4d76-8109-7373fa62b255</guid><dc:creator>scotte</dc:creator><description>csteward... You said you did this.  This is not working as you say. If you leave blank we are getting NO results?  We would like to use the way you mention but no luck. In fact if blank I put the value &amp;quot;%&amp;quot; in the search field. This does not give us the correct results ethier. When using % there it only returns records if a value is in field.?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13664?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 00:13:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:71f0e860-3bee-4e0e-ba5f-ef2686b783d1</guid><dc:creator>scotte</dc:creator><description>We are on release 7.2.   Can someone give me an example of building a  Select Query where using queryrecord or queryentity.  We have 5 fields that may be searchable. The user can search on 1 to 5 of these fields. How is this done?  So the WHERE clause will be dynamic... 1-5 fields. Thanks!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13663?ContentTypeID=1</link><pubDate>Wed, 10 Dec 2014 00:12:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:829844a8-75af-4766-ac64-e8a609125e2d</guid><dc:creator>Chris</dc:creator><description>I&amp;#39;ve accomplished this in the Query DB smart node by including all columns in the WHERE clause with &amp;#39;LIKE&amp;#39;, such as:&lt;br /&gt;&lt;br /&gt;..WHERE Column1 LIKE ac!col1Filter AND Column2 LIKE ac!col2Filter AND Column3 LIKE ac!col3Filter AND Column4 LIKE ac!col4Filter AND Column5 LIKE ac!col5Filter&lt;br /&gt;&lt;br /&gt;You can populate any search variables (one to all) with text, leaving ones not entered blank.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: We have a need to do a select query. The "WHERE" of the SQL statement</title><link>https://community.appian.com/thread/13655?ContentTypeID=1</link><pubDate>Tue, 09 Dec 2014 17:57:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:92ec4956-2f31-48ed-8c1e-26eda742979b</guid><dc:creator>Tim</dc:creator><description>Try using queryentity() or queryrecord() instead. These functions provide much more powerful query options and allow for dynamic where conditions. See the examples here for a starter:&lt;br /&gt;&lt;a href="https://forum.appian.com/suite/help/7.7/Query_Recipes.html"&gt;forum.appian.com/.../Query_Recipes.html&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>