Human-Readable Ranges

Kevin Feasel

2016-08-03

T-SQL

Daniel Hutmacher shows us how to build human-readable ranges of integers and dates:

This is a real-world problem that I came across the other day. In a reporting scenario, I wanted to output a number of values in an easy, human-readable way for a report. But just making a long, comma-separated string of numbers doesn’t really make it very readable. This is particularly true when there are hundreds of values.

So here’s a powerful pattern to solve that task.

I really like this.  It takes the gaps & islands problem and goes one step further.

Related Posts

Comparing Ranking Functions

Doug Kline compares three window functions:  RANK, DENSE_RANK, and ROW_NUMBER: — so let’s say that we’ve created a contest — places in the contest (top place, 2nd place, etc.) — will be determined by the test score — in other words, we’re not so concerned with the raw score — but rather, we’re interested in […]

Read More

Updating Data In Common Table Expressions

Kenneth Fisher shows that you can directly update a table referenced in a common table expression: CTEs are cool things. You can essentially create one or more in-line view(s) within your query. One thing that isn’t overly well known is that you can actually update the data within the CTE. No, I don’t mean using using the UPDATE statement […]

Read More

Categories

August 2016
MTWTFSS
« Jul Sep »
1234567
891011121314
15161718192021
22232425262728
293031