cancel
Showing results for 
Search instead for 
Did you mean: 

SQLCMD Question

richard_thurlow
Participant
0 Kudos

Hello,

I want to run a SQLCMD...

I have the following query I run in SAP B1:

SELECT T0.[CardCode], T0.[Address], T0.[LineNum]

FROM CRD1 T0

JOIN OCRD T1 ON T1.CardCode=T0.CardCode

WHERE T0.[AdresType] ='S' and T0.Address != T1.ShipToDef AND T1.CardCode LIKE '[%0]%'

Here is what I have:

SQLCMD -S <servername> -d <db_name> -U <username> -P <password> -Q "set nocount on;SELECT T0.CardCode, T0.LineNum, T0.Address, T0.Block, T0.Street, T0.City, T0.County, T0.State, T0.ZipCode FROM CRD1 T0 JOIN OCRD T1 ON T1.CardCode=T0.CardCode and T0.[AdresType] ='S' and T0.Address != T1.ShipToDef" -s "," -o "\\network\testing.txt" -h-1 -s"~" -W -w 999

This appears to work - but I just wanted to make sure, can someone please comment on whether this is giving me a export file with all ship-to addresses which aren't the default address?

Regards

Rick

Accepted Solutions (0)

Answers (1)

Answers (1)

Sriram2009
Active Contributor
0 Kudos

Hi Richard


Its not advice to use the SQLCMD at the database level, As SAP best practices to fetch the data you have to use either SAP ABAP coding or BI Query’s.


Regards

SS

richard_thurlow
Participant
0 Kudos

Hi SS,

The reason I am using SQLCMD is that I needed to automate a query to export to TXT or CSV file. This was the first method I came across that allowed me to do that.

Is there some major reason why I shouldn't be doing what I'm doing at a database level?

Happy to be told otherwise as long as you can indicate how I go about this.

Regards

Rick

Sriram2009
Active Contributor
0 Kudos

Hi Richard

   You can create a custom code program to export the spool output to CSV file format. and also you can refer the SAP link  Exporting as a CSV File/Excel File - Business Intelligence - SAP Library

BR

SS