<?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: SQL's WHERE clause priority order? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302735#M1534422</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;It's so funny that you said:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, i dont have SAP, so i can not do a quik test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, with your current query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 SELECT vbeln INTO my_vbeln FROM vbak
WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).  "if i'm not wrong, you will get syntax error in this select query
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's always returns only one record. If you wanted to get all you must declare an internal table to hold your results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 SELECT vbeln INTO TABLE my_itab FROM vbak
WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REgards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Sep 2010 04:51:08 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-09-21T04:51:08Z</dc:date>
    <item>
      <title>SQL's WHERE clause priority order?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302732#M1534419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: My requirement is -- Select a record/sales order from VBAK where AUART = my_doc_type_1&lt;/P&gt;&lt;P&gt;if I do not found any record, then I have to look up as Select a record/sales order from VBAK where AUART = my_doc_type_2&lt;/P&gt;&lt;P&gt;So, am writing the SQL as below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; SELECT vbeln INTO my_vbeln FROM vbak
WHERE auart IN ( my_doc_type_1, my_doc_type_2 ). &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pls. let me know,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) My assumption is that, system FIRST look for my_doc_type_1 record, if it does not found any such, then system will look for my_doc_type_2 record, am I correct? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2)if so, the PRIORITY is in the order in which we hv given in paranthesis?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) Say, there are 2 records with same VBELN (I knew, its impossible having 2 recoords with same key!! just for example) and hving the AUART values as my_doc_type_1 and my_doc_type_2 like below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;12345678 -&lt;/P&gt;&lt;HR originaltext="---" /&gt;&lt;P&gt; my_doc_type_1&lt;/P&gt;&lt;P&gt;12345678 -&lt;/P&gt;&lt;HR originaltext="---" /&gt;&lt;P&gt; my_doc_type_2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, in this case system will select BOTH records?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, i dont have SAP, so i can not do a quik test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 04:03:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302732#M1534419</guid>
      <dc:creator>former_member202077</dc:creator>
      <dc:date>2010-09-21T04:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: SQL's WHERE clause priority order?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302733#M1534420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your select statement will pick all the records fall under the selection criteria.&lt;/P&gt;&lt;P&gt;In ur example it will pick both the records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Guess there is no priority order in Where clause of SELECT statement.&lt;/P&gt;&lt;P&gt;SAP picks all the records satisfying the WHERE condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you can do is :&lt;/P&gt;&lt;P&gt;1. Select where AUART = doc1.&lt;/P&gt;&lt;P&gt;2. if sy-subrc is not initial.&lt;/P&gt;&lt;P&gt;       Select where AUART = doc2.&lt;/P&gt;&lt;P&gt;     endif.&lt;/P&gt;&lt;P&gt;This is like if not found for doc1, check for doc 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;VR.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 04:11:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302733#M1534420</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-21T04:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: SQL's WHERE clause priority order?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302734#M1534421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;This select query will fetch all the records from VBAK having order type as my_doc_type_1 or my_doc_type_2. This answers all your questions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 04:14:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302734#M1534421</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-21T04:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL's WHERE clause priority order?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302735#M1534422</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;It's so funny that you said:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, i dont have SAP, so i can not do a quik test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, with your current query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 SELECT vbeln INTO my_vbeln FROM vbak
WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).  "if i'm not wrong, you will get syntax error in this select query
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's always returns only one record. If you wanted to get all you must declare an internal table to hold your results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 SELECT vbeln INTO TABLE my_itab FROM vbak
WHERE auart IN ( my_doc_type_1, my_doc_type_2 ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REgards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 04:51:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-s-where-clause-priority-order/m-p/7302735#M1534422</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-21T04:51:08Z</dc:date>
    </item>
  </channel>
</rss>

