How To Create a Simple User Defined Function in MS SQL Server?
Submitted by: AdministratorIf you want to create a simple user defined function, you can use the "CREATE FUNCTION" command with a statement block in a simple format as shown in below:
CREATE FUNCTION function_name()
RETURNS data_type
AS BEGIN
statement_1;
statement_2;
...
statement_n;
RETURN expression;
END;
GO
The following tutorial exercise shows you how to create a simple user defined function:
USE GlobalGuideLineDatabase;
GO
CREATE FUNCTION Welcome()
RETURNS VARCHAR(40)
AS BEGIN
RETURN 'Welcome to globalguideline.com';
END;
GO
PRINT dbo.Welcome();
GO
Welcome to globalguideline.com
Submitted by: Administrator
CREATE FUNCTION function_name()
RETURNS data_type
AS BEGIN
statement_1;
statement_2;
...
statement_n;
RETURN expression;
END;
GO
The following tutorial exercise shows you how to create a simple user defined function:
USE GlobalGuideLineDatabase;
GO
CREATE FUNCTION Welcome()
RETURNS VARCHAR(40)
AS BEGIN
RETURN 'Welcome to globalguideline.com';
END;
GO
PRINT dbo.Welcome();
GO
Welcome to globalguideline.com
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Use Subqueries with the IN Operators in MS SQL Server? |
☺ | How To Create a Testing Table with Test Data in MS SQL Server? |
☺ | How To Configure and Test ODBC DSN Settings? |
☺ | How To Create a Large Table with Random Data for Index Testing in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |