TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Narasiman nar
NA
64
22.5k
replace in sql server
May 21 2018 8:45 PM
i writeen one table valued function to split string
create FUNCTION [dbo].[StringSplit](@input NVARCHAR(MAX), @delimiter CHAR(1)=',')
RETURNS @returnTable TABLE(item NVARCHAR(100)) AS
BEGIN
IF @input IS NULL RETURN;
DECLARE @currentStartIndex INT, @currentEndIndex INT,@length INT;
SET @length=LEN(@input);
SET @currentStartIndex=1;
SET @currentEndIndex=CHARINDEX(@delimiter,@input,@currentStartIndex);
WHILE (@currentEndIndex<>0)
BEGIN
INSERT INTO @returnTable VALUES (LTRIM(SUBSTRING(@input, @currentStartIndex, @currentEndIndex-@currentStartIndex)))
SET @currentStartIndex=@currentEndIndex+1;
SET @currentEndIndex=CHARINDEX(@delimiter,@input,@currentStartIndex);
END
IF (@currentStartIndex <= @length)
INSERT INTO @returnTable
VALUES (LTRIM(SUBSTRING(@input, @currentStartIndex, @length-@currentStartIndex+1)));
RETURN;
END;
i am using above function in below select query
DECLARE @testString VARCHAR(100)
SET @testString = replace(replace('{"Product":"algoda","Product2":"Nao","Product3":"Nao1"}','{',''),'}','')
SELECT *
FROM [dbo].[StringSplit](@testString, DEFAULT)
When i execute output as follows
item
"Product1":"algoda"
"Product2":"Nao"
"Product3":"Nao1"
from the above i want output as follows
item
Product1 algoda
Product2 Nao
Product3 Nao
in the above function what changes i have to made to get above excepted output to remove the " and :.
Reply
Answers (
1
)
interview guidance
webconfig connection for mysql?