SQL queries separated by commas; call a custom function

 select col from [dbo].[GetInPara]('101,102,103',',')

 

 

USE [xxx]
GO
/****** Object:  UserDefinedFunction [dbo].[GetInPara]    Script Date: 2019/9/26 11:06:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER   function   [dbo].[GetInPara](@c varchar(2000),@split varchar(2))   
returns  @t   table(col   varchar(20))   
as   
    begin     
      while(charindex(@split,@c)<>0)   
        begin   
          insert   @t(col)   values   (substring(@c,1,charindex(@split,@c)-1))   
          set   @c   =   stuff(@c,1,charindex(@split,@c),'')   
        end   
      insert   @t(col)   values   (@c)   
      return   
    end

 

Guess you like

Origin www.cnblogs.com/enych/p/11589627.html