DEV Community

Cover image for Aggregate SQL output in file in Azure Devops piepline
Antoine
Antoine

Posted on

2 2

Aggregate SQL output in file in Azure Devops piepline

Photo by Sergei Solovev on Unsplash

In order to generate SQL statements based on a reference environment, we had to run multiples stored procedures, and aggregate results in a SQL file.

In order to automate this in a pipeline using Powershell Core Task, i saw this Example on how to manage output of Invoke-SQLCmd.

Then with this command i can append content to a file.

$sqlQuery=@"YOUR_SQL_STATEMENT_MULTILINE"@

$TableResult = Invoke-Sqlcmd -ServerInstance  "$(Server)" -Database "$(Db)" -Username "$(UserLogin)" -Password "$(userPassword)" -OutputAs DataTable -EncryptConnection  -Query $sqlQuery

$TableResult[0].Rows | %{Add-Content -Path .\Output.sql $_[0]}
Enter fullscreen mode Exit fullscreen mode

Hope this helps !

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more