I am using a split list function to handle sending multiple values in a parameter. When I send it a value with an apostraphe, it does not work. I have attached the function below.
Thanks!!!
/****** Object: UserDefinedFunction [SplitList] Script Date: 10/12/2009 13:46:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Function [SplitList]
(
@CommaDelimitedFieldNames Varchar(8000),
@CharToFind VarChar(10)
)
Returns @Tbl_FieldNames Table (Position Integer Identity(1,1), FieldName VarChar(8000)) As
Begin
Set @CommaDelimitedFieldNames = @CommaDelimitedFieldNames + @CharToFind
Declare @Pos1 Int
Declare @pos2 Int
Set @Pos1=1
Set @Pos2=1
While @Pos1<DataLength(@CommaDelimitedFieldNames)
Begin
Set @Pos1 = CharIndex(@CharToFind, @CommaDelimitedFieldNames,@Pos1)
Insert @Tbl_FieldNames Select Cast(Substring(@CommaDelimitedFieldNames,@Pos2,@Pos1-@Pos2) As VarChar(8000))
Set @Pos2=@Pos1+1
Set @Pos1 = @Pos1+1
End
Return
End
Thanks!!!
/****** Object: UserDefinedFunction [SplitList] Script Date: 10/12/2009 13:46:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Function [SplitList]
(
@CommaDelimitedFieldNames Varchar(8000),
@CharToFind VarChar(10)
)
Returns @Tbl_FieldNames Table (Position Integer Identity(1,1), FieldName VarChar(8000)) As
Begin
Set @CommaDelimitedFieldNames = @CommaDelimitedFieldNames + @CharToFind
Declare @Pos1 Int
Declare @pos2 Int
Set @Pos1=1
Set @Pos2=1
While @Pos1<DataLength(@CommaDelimitedFieldNames)
Begin
Set @Pos1 = CharIndex(@CharToFind, @CommaDelimitedFieldNames,@Pos1)
Insert @Tbl_FieldNames Select Cast(Substring(@CommaDelimitedFieldNames,@Pos2,@Pos1-@Pos2) As VarChar(8000))
Set @Pos2=@Pos1+1
Set @Pos1 = @Pos1+1
End
Return
End