Hi friends
I want to know how to create function in SQL Server.
Thank you.
Function in SQL Server
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 7, 2012, 8:57 AM EDT
http://www.techrepublic.com/blog/datacenter/understand-when-to-use-user-defined-functions-in-sql-server/171
Satyapriya NayakRank #47 · 31.5K reputationPosted Jun 7, 2012, 9:14 AM EDT
Please refer the below links
http://www.sqlteam.com/article/user-defined-functions
http://www.functionx.com/sqlserver/functions/create.htm
http://www.simple-talk.com/sql/t-sql-programming/sql-server-functions-the-basics/
Thanks
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 7, 2012, 7:52 PM EDT
There are two types of User-Defined functions in SQL Server.Scalar, Inline Table-Valued and Multi-statement Table-valued.
A Scalar user-defined function returns one of the scalar data types.
CREATE FUNCTION MyValue
(@Value int)
RETURNS varchar(30)
AS
BEGIN
declare @Return varchar(30)
select @return = 'you are Entered: 1'
end
An Inline Table-Value or Multi-statement Table-Value user-defined function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL select command and in essence provide us with a parameterized, non-updateable view of the underlying tables.
CREATE FUNCTION Customers
Please refer(@CustomerId Int)
RETURNS TABLE
AS
RETURN
SELECT * FROM customers
WHERE customerId = @CustomerId
http://msdn.microsoft.com/en-us/library/ms186755.aspx
hope this will help you.