0

We are required to display UID that is in BOS_BARCODE_IT_LOG but not exists in BOS_BARCODE_DO_LOG

The reason that I joined with OITM is because the user asked for the selection Criteria in SAP Business One.

SELECT X0."DATE",X0."ITEMCODE", X0."UID"
FROM "BOS_BARCODE_IT_LOG" X0 JOIN OITM X1 ON

X0."ITEMCODE" = X1."ItemCode"

WHERE
X1."ItemCode" =  '[%0]'

AND  NOT EXISTS (
SELECT X2."UID" FROM "BOS_BARCODE_DO_LOG" X2
WHERE X0."ITEMCODE" = X2."ITEMCODE" AND
X0."UID" = X2."UID" AND
X0."DATE" = X2."DATE"
)

We need that '[%0]' in order to display

enter image description here

The problem is that, when I tried to search any items there, the query returns no result.

What I've tried.

I Select only from one table without OITM, and neverthless, did not provide Query Selection Criteria.

I Tried this as well

SELECT X0."DATE",X0."ITEMCODE", X0."UID"
FROM "BOS_BARCODE_IT_LOG" X0

WHERE 

X0."ITEMCODE" = '[%0]' AND

NOT EXISTS (
SELECT X1."UID" FROM "BOS_BARCODE_DO_LOG" X1
WHERE X0."ITEMCODE" = X1."ITEMCODE" AND
X0."UID" = X1."UID" AND
X0."DATE" = X1."DATE"
)

And it provide error.

1). [SAP AG][LIBODBCHDB DLL][HDBODBC] Syntax error or access violation;257 sql syntax error: incorrect syntax near ")": line 14 col 1 'Received Alerts' (OAIB) (at pos 299)

Another thing, is it possible to use subquery with more than one tables and provide the expected result (Not just blank result)

What I learned in the tutorial that subquery only used for one table. This is one of the examples.

https://www.tutorialspoint.com/sql/sql-sub-queries.htm

Thanks.

1 Answer 1

0

We are required to display UID that is in BOS_BARCODE_IT_LOG but not exists in BOS_BARCODE_DO_LOG.

I don't undersand how your queries actually relate to the question (they have one additional table oitm, and many more columns). From the description of your question it seems like you want:

select bi.uid
from bos_barcode_it_log bi
where not exists (select 1 from bos_barcode_do_log bd where bd.uid = bi.uid)

If you need oitm for filtering, you can join (if there is not more than one row in per itemcode in oitm), or use exists:

select bi.uid
from bos_barcode_it_log bi
where 
    exists (select 1 from oitm o where o.itemcode = bi.itemcode)
    and not exists (select 1 from bos_barcode_do_log bd where bd.uid = bi.uid)
4
  • Yeah, however. I need to join another table called OITM. Is it possible? Would it help if I include the structure of table? Aug 28, 2020 at 14:17
  • @MarioSaputra: I added another query to my answer.
    – GMB
    Aug 28, 2020 at 14:20
  • The other code you add is actually a good code. However, it misses the requirement that I need, the input parameter settings. In SAP, we need to have '[%0]' in the query. I tried to put the '[%0]' in the inner query, and it gave an immediate no result, rather than asking the user to input certain itemcode. The input parameter I mentioned here is provided in the picture from orignal post. Aug 29, 2020 at 16:11
  • Here's what I tried. select bi.uid, bi.ItemCode, bi.date from bos_barcode_it_log bi where exists (select 1 from oitm o where o.itemcode = bi.itemcode and o.itemcode = '[%0]') and not exists (select 1 from bos_barcode_do_log bd where bd.uid = bi.uid) Aug 29, 2020 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.