下面是一个示例函数,用于将一个字符串按照指定的分隔符进行分割: CREATEFUNCTIONdbo.SplitString(@inputStringVARCHAR(MAX),-- 需要分割的字符串@delimiterVARCHAR(1)-- 分隔符)RETURNS@outputTableTABLE(splitValuesVARCHAR(MAX))ASBEGINDECLARE@startINT,@endINTSET@start=1SET@end=CHARINDEX(@delimiter,@inputString)...
下面是一个示例代码: CREATEFUNCTIONdbo.SplitString(@StringNVARCHAR(MAX),@DelimiterCHAR(1))RETURNSTABLEASRETURN(WITHSplit(stpos,endpos)AS(SELECT0ASstpos,CHARINDEX(@Delimiter,@String)ASendposUNIONALLSELECTendpos+1,CHARINDEX(@Delimiter,@String,endpos+1)FROMSplitWHEREendpos>0)SELECTSUBSTRING(@String,stpos,...
如果您的 SQL Server 版本低于 2016,以下是一个自定义的 string_split 函数的示例。这个函数使用了一个数字表来生成一个连续的数字序列,然后用这些数字作为索引来分割字符串。 sql CREATE FUNCTION dbo.SplitStrings_Numbers ( @List NVARCHAR(MAX), @Delimiter NVARCHAR(255) ) RETURNS TABLE WITH SCHEMABINDING AS...
I loaded a text file with a huge amount of delimited data to really get a gauge on time this would take. The string is basically, "data%data%data%data%data" and on. Around 600 indexes. I restarted my local instance of SQL Server 2005 that I did these on to ensure you can see CLR...
returnstr.Value.Split(delimiter[0]); } publicstaticvoidFillRow(objectrow,outSqlString str) { str =newSqlString((string)row); } }; I loaded a text file with a huge amount of delimited data to really get a gauge on time this would take. The string is basically, "data%data%data%data...
Transact-SQL reference for the STRING_SPLIT function. This table-valued function splits a string into substrings based on a character delimiter.
STRING_SPLITinputs a string that has delimited substrings and inputs one character to use as the delimiter or separator. Optionally, the function supports a third argument with a value of0or1that disables or enables, respectively, theordinaloutput column. ...
STRING_SPLIT inputs a string that has delimited substrings and inputs one character to use as the delimiter or separator. Optionally, the function supports a third argument with a value of 0 or 1 that disables or enables, respectively, the ordinal output column.STRING_SPLIT outputs a single-...
STRING_SPLITinputs a string that has delimited substrings and inputs one character to use as the delimiter or separator. Optionally, the function supports a third argument with a value of0or1that disables or enables, respectively, theordinaloutput column. ...
STRING_SPLIT inputs a string that has delimited substrings and inputs one character to use as the delimiter or separator. Optionally, the function supports a third argument with a value of 0 or 1 that disables or enables, respectively, the ordinal output column. STRING_SPLIT outputs a si...