Skip to Content

If Then Else SAP B1 Query

Hello,

I have this query I already use daily:

SELECT T2.[WhsName], T0.[DocDate], T0.[DocEntry] AS 'Order Number', T0.[LineNum], T0.[ItemCode] AS 'Item Code', T0.[Dscription] AS 'Product Name', T0.[Quantity], T0.[LineTotal] AS 'Net Sale'

FROM INV1 T0 INNER JOIN OITM T1 ON T0.[ItemCode] = T1.[ItemCode] INNER JOIN OWHS T2 ON T0.[WhsCode] = T2.[WhsCode] INNER JOIN OINV T3 ON T0.[DocEntry] = T3.[DocEntry]

Trying to create another Column that would categorize document into either Delivery or Store Order. The Document should be considered a Delivery if the ItemCode 'Delivery' appears in the document lines. Is this possible to accomplish through an If Else statement in SAP B1? So far, I hvae tried Case Option, but have not had much luck either.

Also tried below, but did not seem to work either.

IF T0.[ItemCode] = 'Delivery', THEN T3.[DocEntry] = 'Delivery' ELSE 'Store'.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Oct 24, 2019 at 06:07 PM
    CASE WHEN T0.[ItemCode] = 'Delivery' THEN 'Delivery' ELSE 'Store' END
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 25, 2019 at 05:27 AM

    Hi Ismael,

    How about this:

    CASE
     WHEN ISNULL((select distinct 'true' 
                  from INV1 r 
                  where r.DocEntry = T0.DocEntry 
                    and r.ItemCode = 'Delivery'), 'false') = 'true' THEN 'Yes'
     ELSE 'No'
    END AS [Is Delivery]

    Regards,

    Johan

    Add a comment
    10|10000 characters needed characters exceeded

    • Artem Tkachev, same difference indeed. My version is easier to read / understand, your version is cleaner / more efficient.

      However, your version may throw an error if the subquery returns an empty result set. So if we make one more small adjustment, Ismael may want to use your version:

      CASE
       WHEN ISNULL((select distinct 1
                    from INV1 r 
                    where r.DocEntry = T0.DocEntry 
                      and r.ItemCode ='Delivery'), 0) = 1 THEN 'Yes'
       ELSE 'No'
      END AS [Is Delivery]

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.