Last post Jun 30, 2016 06:07 PM by limno
Jun 29, 2016 01:12 PM|smtaqi|LINK
Jun 30, 2016 06:10 AM|eralper|LINK
Please check https://msdn.microsoft.com/en-us/library/ms162773.aspx MSDN article
Invoke is not used when command is executed on SQL Server
In this sample tutorial, I inserted data returned from
SQLCMD into a temp table and used in a SQL Server stored procedure.
And a sample from MSDN is as follows
sqlcmd -d AdventureWorks2012 -Q "SELECT TOP 5 FirstName FROM Person.Person;SELECT TOP 5 LastName FROM Person.Person;"
Jun 30, 2016 06:17 AM|eralper|LINK
If you want to export SQL query results from SQL Server to text file in CSV format, please check
SQL Server BCP command for SQL output to file
Instead of SQLCMD you will be using BCP utility for data export to text file in csv format from SQL Server database query
I hope it helps
Here is how BCP sample looks like, please review the mentioned SQL tutorial for more detail
SET @sql = 'bcp "SELECT ....." queryout "c:\filename.csv" -c -UTF8 -T -Slocalhost'
Jun 30, 2016 06:07 PM|limno|LINK
You can save your powershell script and call it from xp_cmdshell:
EXEC master..xp_cmdshell 'PowerShell.exe "c:\temp\mypsscript.ps1" '