I have a table with a text field. I constructed a query that takes the datalength of those fields and basically returns a histogram.
SELECT TEXTFieldSize, COUNT(TEXTFieldSize) AS Count FROM (SELECT DATALENGTH(data) AS TEXTFieldSize FROM table) AS Fields GROUP BY TEXTFieldSize ORDER BY TEXTFieldSize;
________________
| Length | Count |
| 1 | 5 |
| 3 | 2 |
| 6 | 12 |
|________|_______|
My problem is, that in order to analyse this properly I also need rows for the values that have a count of zero.
SELECT ???
________________
| Length | Count |
| 1 | 5 |
| 2 | 0 |
| 3 | 2 |
| 4 | 0 |
| 5 | 0 |
| 6 | 12 |
|________|_______|
Thanks in advance!
Generate a numbers table (SQL Server way)
The answer: