Hi,I was wondering if the "Volume_display"-column of the following query could be calculated in a more elegant way, preferably without the case. The objective is to display volumes in chunks (Volume_display_limit). Volume_total will decrease randomly until it reaches 0 but the "Volume_display" must always be between 0 and Volume_display_limit but never more than Volume_display_limit. The point of the 999999999 is to always display the full Volume_total, but if this can be done in another way then thats fine. The code provided displays the correct result:DECLARE @table table ( Volume_total decimal (18, 8), Volume_display_limit decimal (18, 8))INSERT INTO @tableSELECT 15000, 1000 UNION ALLSELECT 1026, 500 UNION ALLSELECT 0, 500 UNION ALLSELECT 12050, 999999999SELECT Volume_total, Volume_display_limit, Volume_display = CASE WHEN Volume_total = 0 THEN 0 WHEN Volume_total % Volume_display_limit = 0 THEN Volume_display_limit ELSE (Volume_total % Volume_display_limit) ENDFROM @table
- Lumbago