4

I have a SQL Server 2012 database from which I need to build a daily automated report with graphs. What would be the best solution to create graph?

I was thinking about automating everything with C# and Excel, but I am hoping there would be an better/easier solution.

Thanks

Martin
  • 39,309
  • 62
  • 192
  • 278

7 Answers7

3

I'd humbly recommend a web and data framework my company writes (it's free, open source, and public domain) called PowerShell Pipeworks. This lets you graph with code like this:

Select-Sql -TableName DBTable | Out-Html -AsBarGraph

It also has a cmdlet, Start-At, to run things normally, so your script would be something like

Start-At -Time "9:00 AM" -Everyday -ScriptBlock { 
    Select-Sql -TableName DBTable -ConnectionStringOrSetting SqlConnectionSecretSetting | Select-Object @{Name='DisplayedProperty';Expression={$_.CalculatedValue} | Out-Html -AsBarGraph |New-WebPage -UseJQueryUI | Set-Content $pathToHtmlFile
}
Start-Automating
  • 8,067
  • 2
  • 28
  • 47
1

You can chart any sql query using sqlchart from the command line. e.g. This generates a .png file 730x250:

sqlchart -D stockdb -P 1433 -servertype mssql -host localhost -e "select * from ohlc where sym='AMZN' AND (date > CURDATE()-60)" -o amazon-candlestick-dark.png --chart candlestick --height 250 --width 730 --theme dark 

sql stock chart

Then you can attach that to an email using your standard scripting language. Instructions for emailing on linux are here

Ryan Hamilton
  • 2,601
  • 16
  • 17
1

Try Grafana. You can link it to an SQL database as well. https://grafana.com/

abhi002
  • 71
  • 2
  • 10
0

You can try to get data from SQL using C# and then generate graph using library in Create Excel (.XLS and .XLSX) file from C# (I myself used EPPlus for the graph before). Both steps are very easy and standard.

Community
  • 1
  • 1
Tianyun Ling
  • 1,045
  • 1
  • 9
  • 24
0

Install and design reports in SSRS - email/store them on a schedule.

Powershell is also an option, let me know if you need more details on powershell.

Jimbo
  • 2,529
  • 19
  • 22
0

If you want a "batteries included" solution you can try DBxtra, It can create reports from SQL Server, and other databases, and export or send them by email automatically with the Schedule Server option.

Miguel Garcia
  • 806
  • 5
  • 9
0

Here are details on the powershell solution:

  1. You will need to learn a little powershell ( you will never regret the time spent )
  2. Install Powershell v3.0
  3. Install module Invokesqlquery (this allows easy commuication to sql, can be downloaded from http://powershell4sql.codeplex.com/ )
  4. Check out http://blogs.technet.com/b/richard_macdonald/archive/2009/04/28/3231887.aspx for charting
Jimbo
  • 2,529
  • 19
  • 22