1

In SQL I would like to replace limit n per family with nothing, where n can be 1-100. how do i do that? I tried...

update t set field1 = Replace(field1,'Limit%per family','')

and nothing updated.

2
  • 2
    Which RDBMS / database software are you using? Commented Jun 11, 2015 at 17:57
  • Do you have that string literal in your values for field1? If so, do you not have any spaces in it? It really isn't very clear what you are trying to do here. Commented Jun 11, 2015 at 18:05

1 Answer 1

1

I would use SUBSTRING and CHARINDEX together to accomplish this:

DECLARE @str CHAR(100)
SELECT @str = 'other text Limit 4 per family some more text'

SELECT REPLACE(@str, SUBSTRING(@str,CHARINDEX('Limit', @str), CHARINDEX('family', @str)-6),'')

For me, it returns: "other text some more text"

All you have to do is plug in the last select statement to your update call and replace @str with field1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.