/* Divide the string into multiple records according to the specified delimiter, and return the method of "select * From DBO. f_division_string ('a, BC, DD, E, F, DAF, eee ',', ') */create function dbo. f_division_string (@ STR varchar (4000) -- string to be split, @ separate varchar (100) -- delimiter) returns @ return_table table -- change the number of multi-table values of the auto-increment table, used to return the record set (idx int -- return the index location of the result set, str_name varchar (100) -- split string value) asbegin declare @ count int -- Number of secondary loops, @ separate_len int -- length of the delimiter, @ POS int -- number of times used in the incircle, @ separate_pos int -- set @ STR = ltrim (rtrim (@ Str) set @ separate_len = Len (@ separate) if right (@ STR, @ separate_len) = @ separate begin set @ STR = left (@ STR, Len (@ Str)-@ separate_len) end set @ COUNT = (LEN (@ Str)-len (replace (@ STR, @ separate ,''))) /@ separate_len set @ Pos = 1 while (@ POS <= @ count) -- Insert the in set @ separate_pos = charindex (@ separate, @ Str) insert into @ return_table (idx, str_name) values (@ POs, substring (@ STR, 1, @ separate_pos-1 )) set @ Pos = @ POS + 1 Set @ STR = right (@ STR, Len (@ Str)-@ separate_pos-@ separate_len + 1) -- extract the extracted string from the original string and extract end insert into @ return_table (idx, str_name) -- Insert the last record value values (@ POs, @ Str) returnend