首页 > 代码库 > sql字符串分组

sql字符串分组

create function f_myWord(@s varchar(50))returns varchar(50)  asbegindeclare @i intset @i=1while @i<=3 begin  set @s=SUBSTRING(@s,CHARINDEX(‘,‘,@s)+1,len(@s))  set @i=@i+1endreturn @send--执行的时候就select dbo.f_myWord(列名) from 你的哪个表

 

-- =============================================-- Author:  阿瑞-- Create date: 2008-03-19-- Description: split函数-- Debug:select * from dbo.Fun_Split(‘ABC:BC:C:D:E‘,‘:‘) -- =============================================CREATE FUNCTION [dbo].[Fun_Split] ( @SourceSql varchar(8000),  @StrSeprate varchar(10))RETURNS  @TEMP_Table TABLE (a varchar(100))ASBEGIN  DECLARE @i int  SET @SourceSql=rtrim(ltrim(@SourceSql))  SET @i=charindex(@StrSeprate,@SourceSql)  WHILE @i>=1    BEGIN     INSERT @TEMP_Table VALUES(left(@SourceSql,@i-1))     SET @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)     SET @i=charindex(@StrSeprate,@SourceSql)  END if @SourceSql<>‘/‘   INSERT @TEMP_Table values(@SourceSql) RETURN END

 

 

 

 

调用:select * from dbo.Fun_Split(‘ABC:BC:C:D:E‘,‘:‘)

sql字符串分组