Friday, 23 February 2024

position Function in MSSQL

In Microsoft SQL Server, the equivalent function to find the position of a substring within a string is the CHARINDEX function. The CHARINDEX function returns the starting position of a substring within a string, similar to the POSITION function in other databases.


Here's the syntax of the CHARINDEX function in MSSQL:


CHARINDEX(substring, string)


- substring: The substring to search for within the string.

- string: The string in which to search for the substring.


Example:

SELECT CHARINDEX('world', 'hello world') AS position;


This will return 7, indicating that the substring 'world' starts at the 7th position within the string 'hello world'.

No comments:

Post a Comment