Three types of user-defined functions for SQL Server

Source: Internet
Author: User

Create function fun_a () #标题函数, create function Fun_name () returns OUTPUT_TYPE as begin return value end;
returns int
As
Begin
return 1;
End
Go

Create function Fun_b () #多语句用户定义函数, create function Fun_name () returns @value table (Colum_list) as begin return; end
Returns @tb table (ID int, Name nvarchar (8))
As
Begin
Insert into @tb (id,name) VALUES (1, ' 111 '), (2, ' 222 ');
Return
End
Go


Create function Fun_c () #内联用户定义函数, create function Fun_name () returns table as return select ...;
Returns table
As
Return select 1 as a,2 as b,3 as C;
Go

Three types of user-defined functions for SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.