We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

SAP Business One SQL Query

JonYen
JonYen asked
on
Medium Priority
5,327 Views
Last Modified: 2013-11-23
I need to write a query in SAP B1 which will list all the Invoices which do not have a particular item code at row level.

What I want to see is all Invoices which do not have item code C&P in any of the rows.

I have tried something like this:

SELECT T0.[DocNum], T0.[CardCode], T0.[CardName] FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T1.[ItemCode] NOT Like 'C&P%%'

Unfortunately this brings up every row in every invoice  so if I try and drill down into some orders there are entries for C&P.

I am not used to using SQL but can write some basic queries.  I would normally ask our SAP B1 support company to do something like this but they'll only tell me it is bespoke work and therefore chargeable which I don't have the budget for right now!

Comment
Watch Question

drop the 2nd % sign & try again

NOT like 'C&P%'

Author

Commented:
this did the same thing -  the query is returning every item row where it is not 'C&P', but this doesnt help because when I drill down into most of the invoices they do have C&P; it just doesnt show up on the query results.

OK ... I think I understand.

SELECT T0.[DocNum], T0.[CardCode], T0.[CardName] FROM OINV T0  
Where not exists(Select T1.Inv1 From INV1 T1 ON T0.DocEntry = T1.DocEntry AND T1.[ItemCode] Like 'C&P%')

Open in new window

Author

Commented:
I get error message 'Incorrect Syntax near keyword ON'
KH002.jpg
Oops, sorry!

SELECT T0.[DocNum], T0.[CardCode], T0.[CardName] FROM OINV T0  
Where not exists(Select T1.Inv1 From INV1 T1 WHERE T0.DocEntry = T1.DocEntry AND T1.[ItemCode] Like 'C&P%')

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.