<?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: Using case in select query join in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675953#M2016622</link>
    <description>&lt;P&gt;Here is an example of what it could look like. Of course if you insist on doing it in one select, you can always join ADRC twice (AS a1 + AS a2) with LEFT JOINs. But I wouldn't recommend it. It would be overly complicated to read and you could not do DATE_FROM LE SY-DATUM in the SELECT because it is a LEFT JOIN and no fields from the right-hand table of a LEFT JOIN may appear in the WHERE. This would result in reading more data than needed and having to filter it afterwards.&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;SELECT SINGLE v~adrnr k~adrnr INTO (lv_v_adrnr, lv_k_adrnr)
  FROM vbpa AS v
  JOIN kna1 AS k ON k~kunnr = v~kunnr
 WHERE vbeln = lv_your_vbeln
   AND posnr = lv_your_posnr
   AND parvw = lv_your_parvw.

IF lv_v_adrnr IS NOT INITIAL.
  lv_v_adrnr = lv_k_adrnr.
ENDIF.

IF lv_v_adrnr IS NOT INITIAL.
  SELECT * UP TO 1 ROWS FROM adrc INTO ls_adrc WHERE addrnumber EQ lv_v_adrnr
                                                 AND date_from LE sy-datum.
  ENDSELECT.
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; I hope this helps.&lt;/P&gt;&lt;P&gt;Patrice&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 15:46:03 GMT</pubDate>
    <dc:creator>Patrice</dc:creator>
    <dc:date>2022-11-30T15:46:03Z</dc:date>
    <item>
      <title>Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675945#M2016614</link>
      <description>&lt;P&gt;Hello gurus, I want a select query where if adrnr value is not in vbpa table then I should take it from kna1 table . Using case how to werite the select query ? &lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 16:55:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675945#M2016614</guid>
      <dc:creator>aks778</dc:creator>
      <dc:date>2022-11-28T16:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675946#M2016615</link>
      <description>&lt;P&gt;Thank you for visiting SAP Community to get answers to your questions.&lt;/P&gt;&lt;P&gt;As you're looking to get most out of your community membership, please consider include a profile picture to increase user engagement &amp;amp; additional resources to your reference that can really benefit you:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Profile &lt;A href="https://developers.sap.com/tutorials/community-profile.html"&gt;https://developers.sap.com/tutorials/community-profile.html&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Tips for Questions: &lt;A href="https://community.sap.com/resources/questions-and-answers"&gt;https://community.sap.com/resources/questions-and-answers&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Consider to take our Q&amp;amp;A tutorial at: &lt;A href="https://developers.sap.com/tutorials/community-qa.html" target="_blank"&gt;https://developers.sap.com/tutorials/community-qa.html&lt;/A&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I hope you find this advice useful, and we're happy to have you as part of SAP Community!&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 16:55:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675946#M2016615</guid>
      <dc:creator>AlexGourdet</dc:creator>
      <dc:date>2022-11-28T16:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675947#M2016616</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;You do not provide a lot of information. The answer will depend on a lot of factors: is it an online transaction that processes a single sales document, or do you have a large amount of data to process in a background process? What key are you using to read the data?&lt;/P&gt;&lt;P&gt;But for instance, if you only have a single sales document to process, a single item and a single partner, you can simply join VBPA with KNA1 and compare the two values afterwards. Something like :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT SINGLE v~adrnr k~adrnr INTO (lv_v_adrnr, lv_k_adrnr)
  FROM vbpa AS v
  JOIN kna1 AS k ON k~kunnr = v~kunnr
 WHERE vbeln = lv_your_vbeln
   AND posnr = lv_your_posnr
   AND parvw = lv_your_parvw.

IF lv_v_adrnr IS NOT INITIAL.
* Use ADRNR from VBPA
ELSE.
* Use ADRNR from KNA1
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can also join with table ADRC if necessary.&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Patrice&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 19:33:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675947#M2016616</guid>
      <dc:creator>Patrice</dc:creator>
      <dc:date>2022-11-28T19:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675948#M2016617</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;If the scenario has more than one Sales Document and Partners to be retrieved within related Customers but pay attention VBPA-PERNR when columns VBPA-KUNNR and VBPA-ADRNR are blank.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select 
a~vbeln "Sales Document
a~posnr "Item
a~parvw "Partner function
a~kunnr "Customer
b~adrnr "Address
from VBPA as a INNER JOIN KNA1 as b ON b~kunnr = a~kunnr
appending table it_VBPA_KNA1
for all entries in it_VBAP "Sales document (item)
where a~vbeln eq it_VBAP-vbeln
and a~posnr eq it_VBAP-posnr
and a~parvw in s_parvw[] "range of Partners
and (a~kunnr ne '' and a~adrnr eq ''). "pay attention!!!
endselect.

if sy-subrc eq 0.
...
endif.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Nov 2022 21:40:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675948#M2016617</guid>
      <dc:creator>roberto_forti</dc:creator>
      <dc:date>2022-11-28T21:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675949#M2016618</link>
      <description>&lt;P&gt;Select vbeln&lt;/P&gt;&lt;P&gt;posnr &lt;/P&gt;&lt;P&gt;parvw &lt;/P&gt;&lt;P&gt;kunnr&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;( (CASE WHEN "VBPA-ADRNR" = :is not initial THEN  Select vbeln&lt;/P&gt;&lt;P&gt;posnr &lt;/P&gt;&lt;P&gt;parvw &lt;/P&gt;&lt;P&gt;kunnr&lt;/P&gt;&lt;P&gt;from VBPA where .....&lt;/P&gt;&lt;P&gt;ELSE &lt;/P&gt;&lt;P&gt;Select vbeln&lt;/P&gt;&lt;P&gt;posnr &lt;/P&gt;&lt;P&gt;parvw &lt;/P&gt;&lt;P&gt;kunnr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from KNA1 where .....END) AS "ADNRN"&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 07:24:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675949#M2016618</guid>
      <dc:creator>shantraj6</dc:creator>
      <dc:date>2022-11-29T07:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675950#M2016619</link>
      <description>&lt;P&gt;I will first join vbak and vbap and the I will join with vbpa if vbpa-adrnr value is not null else I will join with kna1 table and finally I will join with adrc table in order to get the results. I can join with either vbpa or kna1 based on vbpa-adrnr is initia or not. We can use case here but I dont know how to do it. And using only one select query &lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 14:14:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675950#M2016619</guid>
      <dc:creator>aks778</dc:creator>
      <dc:date>2022-11-29T14:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675951#M2016620</link>
      <description>&lt;P&gt;Can you please write it syntatically ? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 15:16:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675951#M2016620</guid>
      <dc:creator>aks778</dc:creator>
      <dc:date>2022-11-29T15:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675952#M2016621</link>
      <description>&lt;P&gt;Could you clarify where ADRNR is taken from? Any SELECT to share that we could fix?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 19:52:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675952#M2016621</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-11-29T19:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675953#M2016622</link>
      <description>&lt;P&gt;Here is an example of what it could look like. Of course if you insist on doing it in one select, you can always join ADRC twice (AS a1 + AS a2) with LEFT JOINs. But I wouldn't recommend it. It would be overly complicated to read and you could not do DATE_FROM LE SY-DATUM in the SELECT because it is a LEFT JOIN and no fields from the right-hand table of a LEFT JOIN may appear in the WHERE. This would result in reading more data than needed and having to filter it afterwards.&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;SELECT SINGLE v~adrnr k~adrnr INTO (lv_v_adrnr, lv_k_adrnr)
  FROM vbpa AS v
  JOIN kna1 AS k ON k~kunnr = v~kunnr
 WHERE vbeln = lv_your_vbeln
   AND posnr = lv_your_posnr
   AND parvw = lv_your_parvw.

IF lv_v_adrnr IS NOT INITIAL.
  lv_v_adrnr = lv_k_adrnr.
ENDIF.

IF lv_v_adrnr IS NOT INITIAL.
  SELECT * UP TO 1 ROWS FROM adrc INTO ls_adrc WHERE addrnumber EQ lv_v_adrnr
                                                 AND date_from LE sy-datum.
  ENDSELECT.
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; I hope this helps.&lt;/P&gt;&lt;P&gt;Patrice&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 15:46:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675953#M2016622</guid>
      <dc:creator>Patrice</dc:creator>
      <dc:date>2022-11-30T15:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using case in select query join</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675954#M2016623</link>
      <description>&lt;P&gt;I will first join vbak and vbap and the I will join with vbpa if vbpa-adrnr value is not null else I will join with kna1 table and finally I will join with adrc table in order to get the results. I can join with either vbpa or kna1 based on vbpa-adrnr is initia or not. We can use case here but I dont know how to do it. And using only one select query&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 16:39:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-case-in-select-query-join/m-p/12675954#M2016623</guid>
      <dc:creator>aks778</dc:creator>
      <dc:date>2022-11-30T16:39:07Z</dc:date>
    </item>
  </channel>
</rss>

