Hi friends
I want to know how to create function in SQL Server.
Thank you.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jun 7, 2012, 11:52 PM
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.
Satyapriya NayakPosted Jun 7, 2012, 1:14 PM
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
VulpesPosted Jun 7, 2012, 12:57 PM
http://www.techrepublic.com/blog/datacenter/understand-when-to-use-user-defined-functions-in-sql-server/171