Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 12890

Passing String Which Has Single Quote Row/Value to a Function Returns Double Quoate

$
0
0

Hi, I'm getting weird thing in resultset. When I pass String which has single quote value in it to a split function , it returns rows with double quote. 

For example  following string:

'N gage, Wash 'n Curl,Murray's, Don't-B-Bald

Returns:

''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald

Here is the split function:

CREATE Function [dbo].[fnSplit] (
@List varchar(8000), 
@Delimiter char(1)

Returns @Temp1 Table (
ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
Item varchar(8000) NULL 

As 
Begin 
Declare @item varchar(4000), 
@iPos int 

Set @Delimiter = ISNULL(@Delimiter, ';' ) 
Set @List = RTrim(LTrim(@List)) 

-- check for final delimiter 
If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
Select @List = @List + @Delimiter -- get position of first element 
Select @iPos = Charindex( @Delimiter, @List, 1 ) 
While @iPos > 0 
Begin 
-- get item 
Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 

If @@ERROR <> 0 Break -- remove item form list 
Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
If @@ERROR <> 0 Break -- insert item 
Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
-- get position pf next item 
Select @iPos = Charindex( @Delimiter, @List, 1 ) 
If @@ERROR <> 0 Break 
End 
Return 
End

FYI: I'm getting @List value from a table and passing it as a string to split function.

Any help would be appreciated!


ZK


Viewing all articles
Browse latest Browse all 12890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>