In the SQL Server 2008 R2, high -efficiency segmentation string: complete solution
Extracting and separation values from SQL Server 2008 R2 column segmentation string have always been a challenge for users. Although many solutions were proposed, none of them were successful in this specific version.
Solution:
In order to solve this problem, the following solutions provide a comprehensive function specifically for SQL Server 2008 R2:
To use this function, just use the following grammar queries to query the value:
<code class="language-sql">CREATE FUNCTION dbo.splitstring ( @stringToSplit VARCHAR(MAX) ) RETURNS @returnList TABLE ([Name] [nvarchar] (500)) AS BEGIN DECLARE @name NVARCHAR(255) DECLARE @pos INT WHILE CHARINDEX(',', @stringToSplit) > 0 BEGIN SELECT @pos = CHARINDEX(',', @stringToSplit) SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1) INSERT INTO @returnList SELECT @name SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)-@pos) END INSERT INTO @returnList SELECT @stringToSplit RETURN END</code>
The above is the detailed content of How to Efficiently Split Comma-Separated Strings in SQL Server 2008 R2?. For more information, please follow other related articles on the PHP Chinese website!