?
Solved

FinD and Replace T-SQL Script Needed

Posted on 2006-06-20
3
Medium Priority
?
327 Views
Last Modified: 2007-12-19
I need a SQL script to find all line breaks in a text field and replace them with the string "<br>".  Lets call the field [Users].[TextBlob].  This is for SQL server 2000.
0
Comment
Question by:creativelogic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16943492
Hi creativelogic,

How are your line breaks defined?  Line feed, carriage return, or both?

Regards,

Patrick
0
 

Author Comment

by:creativelogic
ID: 16943511
lets say both
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 16943739
Hi creativelogic,

Here is the query



-- create table Users ( i int, TextBlob text)
-- go
-- insert into Users select '1', 'Hello
-- world
-- this
-- is
-- SQL '

DECLARE @old varchar(20) ,
@new varchar(20)
SELECT @old = char(13),
@new = '<br>'

DECLARE @i int
DECLARE @txtPtr binary(16) ,
    @offset int ,
    @dellen int

SELECT @dellen = len(@old)
SELECT @txtPtr = 0

WHILE @txtPtr IS NOT NULL
BEGIN
    SELECT @txtPtr = null
    SELECT TOP 1 @i = i, @txtPtr = textptr(TextBlob)
    FROM Users
    WHERE TextBlob LIKE '%' + @old + '%'
   
    IF @txtPtr IS NOT NULL
    BEGIN
        SELECT @offset = 1
        WHILE @offset <> 0
        BEGIN
            SELECT @offset = patindex('%' + @old + '%', TextBlob)
            FROM Users
            WHERE i = @i
            --SELECT offset = @offset
           
            IF @offset > 0
            BEGIN
                SELECT @offset = @offset-1
                UPDATETEXT Users.TextBlob @txtPtr @offset @dellen @new
            END
        END -- end while
    END-- End if
END-- end while




SELECT * FROM Users


Aneesh R!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 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