Replace String in Stored Proc

  • Hi,

    I have a quick question.

    I want to replace all the newline characters in one of my collumn with "<br>" when I am fetching the record within my stored procedure. I am not sure how to use Replace function in conjunction with some regular expression.

    This field is directly displayed on webpage via XSLT page. So stored procedure seems best place for this manipulation.

    I would appreciate any help.

    Thanks.

  • Try something like this:

    declare @line varchar(100)

    set @line = 'this is the first line' + char(13) + 'this is the second line'

    select @line

    -- replace line feed with space

    select replace (@line,char(13),' ')

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • Generally thou when data is submitted with an enter in the string it is both the Carriage Return (13) and Line Feed (10) characters so you may want to do

    SET @line = replace(replace(@line, char(13),''), char(10), '<br>')

    to get it properly replaced in the string.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply