-2

I need to run a script saved in my computer through CMD (SQLCMD) and save the result in other file in my computer.

leo stark
  • 1
  • 1
  • If that's what you need to do, what's stopping you? What have you tried so far and why didn't it work? If you've not tried anything, why not? What research did you perform instead and what about it didn't you understand? If you tell us we can help explain it in more simple terms or with further examples. (Also, I recommend using PowerShell over CMD now, especially in a Windows 10 environment, where CMD doesn't really exist anymore.) – Larnu Apr 24 '19 at 16:56

3 Answers3

2

Use SQLCMD to run a script from command line, see:

https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-2017

To save output to a file, look into using pipes for your output, see:

Redirect Windows cmd stdout and stderr to a single file

or

https://helpdeskgeek.com/how-to/redirect-output-from-command-line-to-text-file/

Jon Roberts
  • 1,809
  • 2
  • 9
  • 15
1

You can run the script and then create another backup.

You can try mssql-scripter that is a multiplatform SQL command line tools such as sqlcmd.

Kevin Hernández
  • 598
  • 5
  • 20
0
Use bcp
bcp "SELECT * FROM TABLE" queryout file.csv -t";" -SSERVERNAME -T -c -e errors.txt
Alex M
  • 137
  • 2
  • 6