SQL Server equivalent of substring_index function in MySQL
问题 I am trying to port a query from MySQL to SQL SERVER 2012. How do i write an equivalent for MySQL's substring_index()? MySQL SUBSTRING_INDEX() returns the substring from the given string before a specified number of occurrences of a delimiter. SUBSTRING_INDEX(str, delim, count) SELECT SUBSTRING_INDEX('www.somewebsite.com','.',2); Output: 'www.somewebsite' 回答1: Try this solution based on T-SQL and XQuery( (root/row)[position() <= sql:variable("@count")] ): T-SQL Scalar function: CREATE