<?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: Subquery Error (SAP HANA) in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424511#M4651653</link>
    <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;vando&lt;/SPAN&gt;. I cannot recognize this syntax as HANA SQL. It seams more like MSSQL syntax for variables?&lt;/P&gt;&lt;P&gt;What are you trying to achieve with the parameters? &lt;/P&gt;</description>
    <pubDate>Sat, 15 May 2021 13:38:13 GMT</pubDate>
    <dc:creator>Vitaliy-R</dc:creator>
    <dc:date>2021-05-15T13:38:13Z</dc:date>
    <item>
      <title>Subquery Error (SAP HANA)</title>
      <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaq-p/12424510</link>
      <description>&lt;P&gt;Hey guys!&lt;BR /&gt;&lt;BR /&gt;I'm having difficulty completing this query, because when I insert the (Subqueries) the query gives an error.&lt;BR /&gt;&lt;BR /&gt;If I execute the query without the date parameters, it executes successfully, however if I put the date parameters and leave the subqueries the error ("SWEI) is presented.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;SELECT T1."CardCode" AS "Cod. PN",
T2."DocEntry" AS "Doc. Origem",
'NF ' AS "Tipo de Doc",
T0."DocDueDate" AS "Vencimento",
TJ2."Debit" - TJ2."Credit" AS "Valor Original",

T2."SumApplied" - IFNULL(t2."WtAppld", 0) + (IFNULL(t0."UndOvDiff", 0) / 
    (SELECT COUNT(j."InvoiceId") 
    FROM VPM2 j 
    WHERE j."DocNum" = t2."DocNum")) AS "Valor Pago",

CASE 
        WHEN t0."CashSum" &amp;gt; 0 THEN T0."TaxDate" 
        WHEN t0."CheckSum" &amp;gt; 0 THEN T0."TaxDate" 
        WHEN t0."TrsfrSum" &amp;gt; 0 THEN T0."TrsfrDate" 
        WHEN T0."BoeAbs" IS NOT NULL THEN T6."TaxDate"
ELSE  t0."TrsfrDate"
END AS "Data Pagmto",
CASE 
        WHEN t0."CashSum" &amp;gt; 0 THEN T0."CashAcct"
        WHEN t0."CheckSum" &amp;gt; 0 THEN T0."CheckAcct" 
        WHEN t0."TrsfrSum" &amp;gt; 0 THEN t0."TrsfrAcct"
        WHEN T0."BoeAbs" IS NOT NULL THEN T0."BoeAcc"
        ELSE  t0."TrsfrAcct"
END AS "C.Contabil",

(Select MIN(TT2."AcctName")
FROM OACT TT2
Where T0."CashAcct" = TT2."AcctCode" OR T0."TrsfrAcct" = TT2."AcctCode" OR T0."CheckAcct" = TT2."AcctCode" OR T0."BoeAcc" = TT2."AcctCode") AS "Nome da Conta Contabil",
T0."DocNum" AS "Doc. Baixa",

T0."DocNum" AS "Doc. Baixa",
CASE 
        WHEN T0."BoeAbs" IS NOT NULL THEN 'Boleto' 
        ELSE 
        CASE 
            WHEN t0."CheckSum" &amp;gt; 0 THEN 'Cheque' 
            WHEN t0."TrsfrSum" &amp;gt; 0 THEN 'Transferencia' 
            WHEN t0."CashSum" &amp;gt; 0 THEN 'Dinheiro' 
            ELSE 'Cartao Credito' 
        END 
    END AS "Forma Pagmto",
T0."BPLId", 
CASE
        WHEN T0."BPLId" = '1' THEN 'CE'
        WHEN T0."BPLId" = '2' THEN 'RN'
        WHEN T0."BPLId" = '3' THEN 'BA'
        WHEN T0."BPLId" = '4' THEN 'PB'        
END AS "Unidade"
 
FROM OVPM T0 
    INNER JOIN OCRD T1 ON T0."CardCode" = T1."CardCode" 
    INNER JOIN VPM2 T2 ON T2."DocNum" = T0."DocNum" AND T2."InvType" = '18' 
    LEFT OUTER JOIN OPCH T3 ON T3."DocEntry" = T2."DocEntry" 
    LEFT OUTER JOIN OBOE T4 ON T4."BoeKey" = T0."BoeAbs" 
    LEFT OUTER JOIN BOT1 T5 ON T5."BOENumber" = T4."BoeNum" 
    LEFT OUTER JOIN OBOT T6 ON T6."AbsEntry" = T5."AbsEntry" 
    INNER JOIN OJDT TJ1 ON TJ1."CreatedBy" = T3."DocEntry" AND TJ1."TransType" = '18' 
    INNER JOIN JDT1 TJ2 ON TJ2."TransId" = TJ1."TransId" AND TJ2."ShortName" = T1."CardCode"  AND TJ2."TransType" = '18' 
   
WHERE T0."Canceled" = 'N' AND (T4."BoeStatus" = 'P' OR T0."BoeAbs" IS NULL) AND 
    CASE 
        WHEN T5."BoeType" IS NOT NULL THEN T5."BoeType" 
        ELSE 'O' 
    END = 'O' AND 
    CASE 
        WHEN T6."StatusTo" IS NOT NULL THEN T6."StatusTo" 
        ELSE 'P' 
    END = 'P' 
    AND T0."BoeAbs" IS NULL    
    
                AND
    T0."DocDueDate" &amp;gt;= [%0] AND  
    T0."DocDueDate" &amp;lt;= [%1]&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I left the subconstants and dates separate, to make the visualization better.&lt;/P&gt;
  &lt;P&gt;In doing some research on the forum, I saw some comments that SAP HANA has difficulties in interpreting date searches with multiple subqueries. And what they recommended in some cases was declaring variables, however when trying to always give an error in SAP HANA.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;/*SELECT * FROM OINV T0*/
declare @FromDate date
declare @ToDate date
/* WHERE */
set @FromDate = /* T0.DocDate */‘[%0]’
set @ToDate =/* T0.DocDate */ ‘[%1]’&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;OR&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Declare FromDate date;
Declare ToDate date;
/*SELECT * FROM OINV T0*/
/* WHERE */
set @FromDate = /* T0.DocDate */ '[%0]'
set @ToDate = /* T0.DocDate */ '[%1]'
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I crashed and I don't know what else to do!&lt;BR /&gt;I ask the experts for help, pointing out that my database is SAP HANA.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2021 12:12:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaq-p/12424510</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-15T12:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery Error (SAP HANA)</title>
      <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424511#M4651653</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;vando&lt;/SPAN&gt;. I cannot recognize this syntax as HANA SQL. It seams more like MSSQL syntax for variables?&lt;/P&gt;&lt;P&gt;What are you trying to achieve with the parameters? &lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2021 13:38:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424511#M4651653</guid>
      <dc:creator>Vitaliy-R</dc:creator>
      <dc:date>2021-05-15T13:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery Error (SAP HANA)</title>
      <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424512#M4651654</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;witalij&lt;/SPAN&gt;  &lt;/P&gt;&lt;P&gt;I want to put a filter by dates.&lt;BR /&gt;For example&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;t0. "DocDueDate"&amp;gt; = [% 0] and t0. "DocDueDate"  &amp;lt;= [%1]
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I put a predefined date, the query is executed successfully.&lt;BR /&gt;For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;AND T0."DocDueDate" &amp;gt;= (TO_TIMESTAMP('20210505', 'YYYYMMDD') )  AND  
    T0."DocDueDate" &amp;lt;= (TO_TIMESTAMP('20210510', 'YYYYMMDD') )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I put [% 0] the query gives an error.&lt;/P&gt;&lt;P&gt;The main table is the OVPM (T0).&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2021 14:41:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424512#M4651654</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-15T14:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery Error (SAP HANA)</title>
      <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424513#M4651655</link>
      <description>&lt;P&gt;Hey guys!&lt;BR /&gt;Any more tips?&lt;/P&gt;</description>
      <pubDate>Sun, 16 May 2021 15:15:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424513#M4651655</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-16T15:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery Error (SAP HANA)</title>
      <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424514#M4651656</link>
      <description>&lt;P&gt;A better tag will be "SAP Business One" even if it is running on HANA.&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 12:32:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424514#M4651656</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-17T12:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery Error (SAP HANA)</title>
      <link>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424515#M4651657</link>
      <description>&lt;P&gt;Thanks for your help  Former Member!&lt;BR /&gt;&lt;BR /&gt;This is really the principle and making an adjustment in the consultation to execute at Base Hana worked.&lt;BR /&gt;I will leave the result assertive so that everyone who comes to analyze can have a right path to follow.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; Base &lt;/STRONG&gt;&lt;STRONG&gt;Query HANA:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/*SELECT * FROM "OVPM" T33*/

Declare FromDate timestamp;
Declare ToDate timestamp;

FromDate := /* T33."DocDueDate" */ '[%0]';
ToDate := /* T33."DocDueDate" */ '[%1]';

SELECT "QUERY"...
.
.
.
AND t0."DocDueDate" BETWEEN FromDate AND ToDate;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 13:48:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/subquery-error-sap-hana/qaa-p/12424515#M4651657</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-19T13:48:49Z</dc:date>
    </item>
  </channel>
</rss>

