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!

functions 1

Status
Not open for further replies.

Cagliostro

Programmer
Sep 13, 2000
4,226
GB
Hi,
I've just installed SQLServer2k. Can you tell e what the syntax for creating functions is? John Fill
1c.bmp


ivfmd@mail.md
 
(I accidentally created a post instead of replying to your post - whoops!)

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top