How to Draw Line Graphs in SSMS

Ever just need a quick visualization of some numbers to get a rough idea of the trend, like this:

SSMS spatial results graph

Option 1: ask Copilot to write the query for you.

In SSMS v22.3 and newer, with the results query on your screen, open up SSMS Copilot and copy/paste this into the prompt:

Given the query in this window, graph the results as a line chart in the SSMS Spatial Results tab using these rules:
1. Wrap the original query in a CTE called SourceData
2. Create a ScaledData CTE that scales X values to 0–300 and Y values to 0–100 using window functions MIN/MAX OVER()
3. Build a LINESTRING geometry from the scaled points
4. Use STDifference to cut holes in the line where data points are, so tooltips don’t conflict
5. Use STBuffer(3) to make each data point a large circle
6. UNION ALL the line (with holes) and the circles, with the line row having NULL for all non-geometry columns
7. The first column in the SELECT should be the X-axis label, the second column should be the Y-axis measure, and the third column should be the geometry — so tooltips show meaningful data when hovering over circles

Use a large model (like Claude Opus 4.6 or newer) for the best results. It’ll write the query for you, and if you’ve been living your life right, you’ll get something like this:

Voila! Graph. Un-check the “Show grid lines” box on the SSMS results tab because the X/Y axis won’t make sense.

Option 2: use this user-defined function.

I asked Copilot to bundle this into a reusable piece of code so that I could use it for any query. It sets up a user-defined table type, then a function that accepts that user-defined table type as an input parameter:

To use it, insert your data into the user-defined table type. In this example below, I’m loading in the top 10 biggest locations in the Stack Overflow Users table:

And voila:

Spatial graph in SSMS

Line charts don’t make as much sense for that particular set of data – you’d probably want bar charts or column charts instead. I’ll leave that to you and your robot friend to work on.

If you wanna watch me work through this with Copilot to come up with the queries, here’s a video of me working on it. Enjoy!

And no, this isn’t my April Fool’s post, hahaha. This does actually work – although I obviously wouldn’t recommend it for any end-user-facing stuff. It’s just fun to have a nice, quick, easy visualization that you can copy/paste into emails or presentations.

Previous Post
I’m Coming to the PASS Summit in Frankfurt!
Next Post
SQL Server 2025 CU4 Adds Automatic Updates

1 Comment. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.