Question

I use SAP B1 at work and want to export a CSV file in a batch file so that I can schedule the export every 15 minutes to be uploaded to a website.

This is what I have at the moment:

SQLCMD -S SERVER-VMSQL -d SBO_COMPANYNAME -U sa -P adminpassword -Q "SELECT ItemCode, FrgnName, OnHand-IsCommited FROM OITM" -s "," -o "\\server-address\users\rick\TestBat.csv" -h-1 -s"," -W -w 999

This gives me an export of a CSV with the columns:

  • Item Code
  • Item Name
  • Qty on hand less qty on sales orders

What I need is to elaborate on this query to put in some WHERE clauses - for example WHERE:

  • U_Category = 'Toys' (where U_Category is a user defined field)
  • Qrygroup2 = 'Y'

All of the above fields are within the OITM table.

Also - how do you join tables with SQLCMD queries? I need to be able to join the OITW table to be able to specify in the WHERE clause that T1.[WhsCode] = '01. Main'.

Any help would be greatly appreciated!

Regards Rick

Était-ce utile?

La solution

There's nothing to prevent you from using WHERE and JOIN clauses in the queries that you supply to SQLCMD. They're just regular SQL queries.

For example, here is the query you provided modified to include the restrictions you specified:

SELECT OITM.ItemCode, OITM.FrgnName, OITM.OnHand-OITM.IsCommited
FROM OITM
   INNER JOIN OITW
       ON OITW.ItemCode = OITM.ItemCode
WHERE OITM.U_Category = 'Toys'
    AND OITM.Qrygroup2 = 'Y'
    AND OITW.WhsCode = '01. Main'

You would just supply this query to SQLCMD, as you did with the query in your OP:

SQLCMD -S SERVER-VMSQL -d SBO_COMPANYNAME -U sa -P adminpassword -Q "SELECT OITM.ItemCode, OITM.FrgnName, OITM.OnHand-OITM.IsCommited FROM OITM INNER JOIN OITW ON OITW.ItemCode = OITM.ItemCode WHERE OITM.U_Category = 'Toys' AND OITM.Qrygroup2 = 'Y' AND OITW.WhsCode = '01. Main'" -s "," -o "\\server-address\users\rick\TestBat.csv" -h-1 -s"," -W -w 999

Autres conseils

Can you clarify what you're trying to do a little more? I've written VB.NET code and made batch files to execute that code every x minutes with windows task scheduler.

You mention the OITM table, but there's also the ITM1 table to consider, I find that joining these two tables in the same query usually gives me everything I need (in terms of data) to apply the correct where clauses for validation.

Again, apologies for not fully understanding your problem but if you can elaborate on the issue a little more I'd be happy to do my best to help.

Cal.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top