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 !

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay