SQL. How to output plural endings (5 orders, 3 orders)

Use function as_countEnding

create FUNCTION [dbo].[as_countEnding]  -- gives the end of the word 3 orders, 7 orders
(
    @num as int
)
RETURNS varchar(500)
AS
BEGIN
  DECLARE @res as nvarchar(10),@digit int

  set @digit = cast(RIGHT(cast(@num as nvarchar),1) as int)
  set @res = case
	when @digit in (1) then N''
	when @digit in (2,3,4) then N'а'
	when @digit in (5,6,7,8,9,0) then N'ов'
   end


  RETURN @res
END

Implementation: 

select [dbo].[as_countEnding](123) -- returns 'а'
Falcon Space is a functional web development platform on a narrow stack MS SQL/Bootstrap. Falcon Space Gettting started

Falcon Space Platform

This is a reduction in the cost of ownership

at the expense of fewer people to support

This is a quick change

while using the program

This is a modern interface

full adaptation for mobile devices

 
Note