Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Replace same more then one character in one column in sql.

Data column: 'BLACKHEATH 0AA BLACKHEATH COLCHESTER CO2 0AA '

But I want like this

BLACKHEATH COLCHESTER CO2 0AA
please help i want UDF function and query how do this SQL Server
Posted

This site is not a "code to order" service.

The only code you get is the code YOU write. Try it yourself. You may find that it's not that hard.
 
Share this answer
 
Comments
Schatak 21-Oct-15 4:14am    
+5
REATE FUNCTION fnmyfunction
(
@Input NVARCHAR(MAX),
@Character CHAR(1)
)
RETURNS @Output TABLE (
Item NVARCHAR(1000)
)
AS
BEGIN
DECLARE @StartIndex INT, @EndIndex INT

SET @StartIndex = 1
IF SUBSTRING(@Input, LEN(@Input) - 1, LEN(@Input)) <> @Character
BEGIN
SET @Input = @Input + @Character
END

WHILE CHARINDEX(@Character, @Input) > 0
BEGIN
SET @EndIndex = CHARINDEX(@Character, @Input)

INSERT INTO @Output(Item)
SELECT UNION( SUBSTRING(@Input, @StartIndex, @EndIndex - 1))

SET @Input = SUBSTRING(@Input, @EndIndex + 1, LEN(@Input))
END

RETURN
END
GO
how i remove more then one word and how to compare string
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900