A function is a block of code that has a name and it has a property that it is reusable. We use function in store Procedure and queries in sql server.
We can define function like-
User Define function - It is created by user and use in any query and SP also.
System Define function- Most of the function define by System in SQL inbuilt function.
We can define function like-
User Define function - It is created by user and use in any query and SP also.
System Define function- Most of the function define by System in SQL inbuilt function.
SQL Function
Scalar Functions
Scalar functions is a function where it is return a single value. Below is the list of some useful Sql Server Scalar functions.
UCASE()
LCASE()
ABS()
RAND()
ROUND()
UPPER()
LOWER()
LTRIM()
LEN()
FORMAT()
NOW()
LCASE()
ABS()
RAND()
ROUND()
UPPER()
LOWER()
LTRIM()
LEN()
FORMAT()
NOW()
SQL Aggregate Function
SQL Aggregate functions return a single value, calculated from values in a column.
AVG()
COUNT()
SUM()
MAX()
MIN()
COUNT()
SUM()
MAX()
MIN()
Detail Discription as below with example
AVG() - This function returns the average value of a numeric column in SQL Server.
SELECT AVG(columnName) FROM TableName
Example
SELECT AVG(Salary) AS Salary FROM Customer
We Create a Table Customer Insert Some Column Table look like as below -
Created Table Customer and we apply AVG of Salary in Customer table then use AVG function and easily find avg of salary like-
Note- In This Example Salary is ColumnName and Customer is TableName Find Avg of salary in customer table and see output as below-
We Create a Table Customer Insert Some Column Table look like as below -
Created Table Customer and we apply AVG of Salary in Customer table then use AVG function and easily find avg of salary like-
Note- In This Example Salary is ColumnName and Customer is TableName Find Avg of salary in customer table and see output as below-
COUNT() - This function is used to count total number of value and return total row in SQL Server.
SQL COUNT() Syntax-
SELECT COUNT(columnName) FROM TableName
SELECT COUNT(columnName) FROM TableName
SQL SUM() Syntax-
SELECT SUM(columnName) FROM TableName
SELECT SUM(columnName) FROM TableName
MAX() - This function returns the Max or largest value of the selected column in SQL Server.
SQL MAX() Syntax-
SELECT MAX(columnName) FROM TableName
SELECT MAX(columnName) FROM TableName
MIN() - This function returns the Minimum value of the selected column in SQL Server.
SQL MIN() Syntax-
SELECT MIN(columnName) FROM TableName
SELECT MIN(columnName) FROM TableName
0 comments :
Post a Comment