Pre-Defined Functions in SQL Server
SQL Server provides a wide range of predefined functions that can be used to perform various operations on data. These functions can be categorized into several types based on their functionality. Here are some commonly used predefined functions in SQL Server:
-
Scalar Functions:
-
•LEN: Returns the length of a string.
-
•LOWER: Converts a string to lowercase.
-
•UPPER: Converts a string to uppercase.
-
•LTRIM: Removes leading spaces from a string.
-
•RTRIM: Removes trailing spaces from a string.
-
•SUBSTRING: Extracts a substring from a string.
-
•CONVERT: Converts a value from one data type to another.
-
•GETDATE: Returns the current system date and time.
-
Aggregate Functions:
-
•SUM: Calculates the sum of a column.
-
•AVG: Calculates the average of a column.
-
•COUNT: Counts the number of rows in a table or a column.
-
•MAX: Returns the maximum value in a column.
-
•MIN: Returns the minimum value in a column.
-
•GROUP BY: Groups rows based on a specified column.
-
Date and Time Functions:
-
•DATEPART: Extracts a specific part (year, month, day, etc.) from a date.
-
•DATEDIFF: Calculates the difference between two dates.
-
•DATEADD: Adds or subtracts a specific time interval to a date.
-
•GETDATE: Returns the current system date and time.
-
•SYSDATETIME: Returns the current system date and time with higher precision
-
String Functions:
-
•CHARINDEX: Returns the starting position of a substring within a string.
-
•REPLACE: Replaces all occurrences of a specified string within another string.
-
•LEFT: Returns a specified number of characters from the left of a string.
-
•RIGHT: Returns a specified number of characters from the right of a string.
-
•STUFF: Deletes a specified length of characters from a string and then inserts another set of characters at a specified position.
-
Conversion Functions:
-
•CAST: Converts a value from one data type to another.
-
•CONVERT: Converts a value from one data type to another.
-
•PARSE: Converts a string to a specified data type.
These are just a few examples of the predefined functions available in SQL Server. There are many more functions that provide different functionalities and can be used to manipulate and analyze data in SQL Server.