SQL 以逗号分隔查询;调用自定义函数

 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

 

你可能感兴趣的:(SQL 以逗号分隔查询;调用自定义函数)