Sql Stored Procedure that can replace characters in a string

Posted on 2006-05-18
Last Modified: 2011-10-03
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:


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

Any ideas?
Question by:JoanHerrick

    Expert Comment

    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>','')
    LVL 50

    Accepted Solution

    like this..
    select replace(replace(yourcolumn,'<vo>',''),'</vo>','') as Yourcolumnname

    Author Comment

    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.  

    Expert Comment

    could have at least split them......

    Author Comment

    I agree, I should have split them.  You both answered very quickly and both were correct.  Should have given you points charlob.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now