Here is a silly little function that I created. It takes any integer from 0-99 and returns a 2 character string. For instance, if the number sent over is 13 then '13'
is returned. If the number passed over is 5 then '05' is returned. I needed for some string manipulation and I thought it would be good practice for writing my first function. Its now my template so I hope it helps you:
**********************************************************
create function fn_make2char
(
@value int
)
returns varchar(2)
as
BEGIN
declare @charvalue varchar(2)
select @charvalue = @value
if len(@charvalue) = 1 select @charvalue = '0' + @charvalue
return(@charvalue)
END
is returned. If the number passed over is 5 then '05' is returned. I needed for some string manipulation and I thought it would be good practice for writing my first function. Its now my template so I hope it helps you:
**********************************************************
create function fn_make2char
(
@value int
)
returns varchar(2)
as
BEGIN
declare @charvalue varchar(2)
select @charvalue = @value
if len(@charvalue) = 1 select @charvalue = '0' + @charvalue
return(@charvalue)
END