Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Example

Status
Not open for further replies.

jkb17

Programmer
Nov 27, 2000
156
US
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




 
Also you can have: right('0'+ @charvalue,2) which is quite neat I find
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top