[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

Sql Stored Procedure that can replace characters in a string

I have a Sql stored procedure that selects a certain column from a table.  I would like to replace some of the characters in the results of that selection.

The extra characters appear at the beginning, middle and end of the string.  Something like this:

<vo>Text1</vo><vo>Text2</vo>

I don't want the <vo>'s and </vo>'s to appear in my results.

Any ideas?
0
JoanHerrick
Asked:
JoanHerrick
  • 2
  • 2
1 Solution
 
charlobCommented:
T-SQL has a  function called REPLACE.

What this does is look for the occurances of a specified string in your target and replace it with another one.

<result> = replace(<source>, ' ', '_')  

So given your example we could use as such:

Select  replace(replace('<vo>Text1</vo><vo>Text2</vo>','<vo>',''),'</vo>','')
0
 
LowfatspreadCommented:
like this..
select replace(replace(yourcolumn,'<vo>',''),'</vo>','') as Yourcolumnname
0
 
JoanHerrickAuthor Commented:
Works perfect - thanks!  
The reason I'm awarding this to Lowfatspread is because you referenced the column name - that was the piece I was struggling with.  
0
 
charlobCommented:
could have at least split them......
0
 
JoanHerrickAuthor Commented:
I agree, I should have split them.  You both answered very quickly and both were correct.  Should have given you points charlob.  
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now