In Microsoft SQL Server (MSSQL), the equivalent function to SUBSTR() is SUBSTRING(). The SUBSTRING() function is used to extract a substring from a string based on a specified starting position and length.
Here's the syntax for the SUBSTRING() function:
SUBSTRING(string_expression, start, length)
- string_expression: The string from which the substring will be extracted.
- start: The starting position from which to extract the substring. It is 1-based (the first character in the string has a position of 1).
- length: The length of the substring to extract. If not specified, the substring extends to the end of the string.
Let's see an example to illustrate how to use the SUBSTRING() function in MSSQL:
Suppose we have a string 'Hello, World!' and we want to extract a substring starting from the 7th position and extending to the end of the string:
SELECT SUBSTRING('Hello, World!', 7, LEN('Hello, World!')) AS extracted_string;
This query will return 'World!' as the extracted substring.
Now, let's say we want to extract only the first 5 characters from the string:
SELECT SUBSTRING('Hello, World!', 1, 5) AS extracted_string;
This query will return 'Hello' as the extracted substring.
So, the SUBSTRING() function in MSSQL allows you to extract substrings from strings based on specified starting positions and lengths.
No comments:
Post a Comment