Drake0727
Drake0727

Reputation: 113

SQL Deleting/Replacing a part of a string

Hello I have a problem

I have Column data in string format in this format:

xxxxxxxx <***********>

I want to pertain the xxxxxxx, but get rid of <***********>, where <***********> could be any type of string of any length.

I have this command so far, but I cant wrap my head around the rest of it.

update Claims
set ClaimInitiatedBy = REPLACE(ClaimInitiatedBy,LIKE '% <%>','')
where ClaimInitiatedBy LIKE '% <%>'

This command doesn't work, and I know it's because of the 2nd parameter in the REPLACE function. What should be the 2nd parameter be for this to work?

I'm using SQL Server 2008, if that matters.

Thanks for the help.

Upvotes: 2

Views: 424

Answers (2)

elopez
elopez

Reputation: 109

try this

SELECT REPLACE('abcdefghicde','cde','xxx');

will return abxxxfghixxx

Arguments:

REPLACE ( string_expression , string_pattern , string_replacement )

string_expression

Is the string expression to be searched. string_expression can be of a character or binary data type.

string_pattern

Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string ('').

string_replacement

Is the replacement string. string_replacement can be of a character or binary data type.

Upvotes: 0

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171529

declare @s as varchar(50)
set @s = 'axxxxxxxx <*****>'
select substring(@s, 1, charindex('<', @s) - 1)

Output:

axxxxxxxx 

Upvotes: 3

Related Questions