UFN_DAYOFMONTH_DESCRIPTION
Returns a description for the day of month
Return
Return Type |
---|
nvarchar(10) |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@DAYOFMONTH | smallint | IN |
Definition
Copy
CREATE function dbo.UFN_DAYOFMONTH_DESCRIPTION(
@DAYOFMONTH smallint = NULL
)
returns nvarchar(10)
with execute as caller
as begin
declare @DESC nvarchar(10);
declare @MOD smallint;
if @DAYOFMONTH=29
set @DAYOFMONTH=NULL;
set @MOD = @DAYOFMONTH % 10;
if (@DAYOFMONTH>3 and @DAYOFMONTH<20) or (@MOD=0 or @MOD>=4)
set @DESC = CONVERT(nvarchar,@DAYOFMONTH) + 'th';
else if @DAYOFMONTH = 1
set @DESC = 'First';
else if @MOD = 1
set @DESC = CONVERT(nvarchar,@DAYOFMONTH) + 'st';
else if @MOD = 2
set @DESC = CONVERT(nvarchar,@DAYOFMONTH) + 'nd';
else if @MOD = 3
set @DESC = CONVERT(nvarchar,@DAYOFMONTH) + 'rd';
else
set @DESC = 'Last';
return @DESC;
end