创建函数: )) --@str:目标字符串 --@spliter:分隔符 RETURNS @tb TABLE(ch NVARCHAR(max)) AS BEGIN DECLARE @Num INT,@Pos INT, @NextPos INT WHILE(@Pos <= LEN(@str)) BEGIN SELECT @NextPos = CHARINDEX(@spliter, @str, @Pos) OR @NextPos IS NULL) INSERT INTO @tb VALUES(RTR…
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --DEClARE @str varchar(500)='a,b2,v5,d3,ew,2,3,dd' --select [dbo].[split](@str,',',8) CREATE FUNCTION [dbo].[split] (),),@no int ) ) AS BEGIN declare @intLen int declare @count int declare @indexb int…
declare @relation_code nvarchar(1024) set @relation_code = '#10000#10002' set @relation_code=substring(@relation_code,2,len(@relation_code)) select @relation_code set @relation_code=@relation_code+'#' declare @cID varchar(100) declare @cEidx int whil…
ALTER FUNCTION dbo.fn_Split ( ), ) ) RETURNS @table_Value TABLE ( SortNo ,) NOT NULL, Value ) COLLATE SQL_Latin1_General_CP1_CI_AS DEFAULT '' ) AS BEGIN --============ DECLARE LOCAL VARIABLE TO USE =============================== DECLARE @intEndpos B…
--方法1 --sql 分隔字符串,返回个数 CREATE function f_splitLen_1 ( @str varchar(1024), --要分割的字符串 @split varchar(10) --分隔符号 ) returns int as begin declare @location int declare @start int declare @length int set @str=ltrim(rtrim(@str)) set @locatio…