0

Id like to run mssql queries in a bash script with tsql command. Thats okay, i can connect and run manualy. I tried to save the result to a file with this script but no success.

> tsql -connection parameters- < tsql_input.sql > tsql_output.csv

where tsql_input.sql is :

select ... from .... ;

or

> tsql -connection parameters- < sql_cmd

where sql_cmd is :

echo "SELECT ... FROM ...;\n
GO\n
exit\n
" > out.csv

What did I miss ?

gszabo
  • 11
  • 4

1 Answers1

1

Use bcp.exe https://msdn.microsoft.com/de-de/library/ms162802(v=sql.120).aspx

Sample: bcp.exe "SELECT Name FROM AdventureWorks.Sales.Currency" queryout Currency.Name.dat -T -c

Frank
  • 1,901
  • 20
  • 27