I want to group the data from one of the tables in a SQL database. The field to be used for grouping is numerical and the groups I want do not follow any mathematical formula e.g.
Group 0 value unknown (NULL)
Group 1 values 0 – 499
Group 2 value 500 – 999
Group 3 value 1000 – 1999
Group 4 value 2000 – 4999
Group 5 value 5000 +
How can I achieve this with TSQL?
By the way I want to do this to display in a Crystal Report, so if there is a better way of doing this in Crystal Reports rather than through the SQL Select statement then please advise.
You can use a
caseto create a custom group. If you define thecasein a subquery, you don’t have to repeat the definition: