dbo.fn_ParseCSVString

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Null on Null Input

False

Schema Bound

False

Assembly

Parameters

Name Data Type Length Description
@CSVString varchar 8000
@Delimiter varchar 10

SQL Script

SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE function dbo.fn_ParseCSVString
(
@CSVString  varchar(8000) ,
@Delimiter varchar(10)
)
returns @tbl table (f_result varchar(1000))
as
/* select * from dbo.fn_ParseCSVString ('qwe,c,rew,c,wer', ',c,') */
begin
declare @i int ,
 @j int
 select  @i = 1
 while @i <= len(@CSVString)
 begin
  select @j = charindex(@Delimiter, @CSVString, @i)
  if @j = 0
  begin
   select @j = len(@CSVString) + 1
  end
  insert @tbl select substring(@CSVString, @i, @j - @i)
  select @i = @j + len(@Delimiter)
 end
 return
end


GO

Depends On

No items found