SQL ntext data type character substitution implementation code _MSSQL

Source: Internet
Author: User
Copy Code code as follows:

---ntext data type character substitution

CREATE TABLE TT
(
Sid INT IDENTITY (1,1),
Cont ntext
)
Go

INSERT INTO TT (cont) VALUES (N ' fd sad FDSA tu Poly Ensemble Computer Information Technology Co., Ltd. possibilities Orange ')
Go
Update TT set cont= ' FD sad FDSA ensemble possibility associate friend Computer Information Technology Co., Ltd. Orange ' where sid=1

--Go to space
EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
--sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
Go
DECLARE @ptrval binary, @i int,@k int,@f int
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (Spaces (1), cont) from TT where sid=1---spaces (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f 1 null
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go
--sp_dboption ' pubs ', ' select Into/bulkcopy ', ' false '
EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' false '
Go

SELECT * from TT

---change English alphabet
EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '

Go
DECLARE @ptrval binary, @i int,@k int,@f int
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (' sad ', cont) from the TT where sid=1---space (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f 3 ' GGG '
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go
SELECT * from TT

---Chinese letters
EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
Go
DECLARE @ptrval binary, @i int,@k int,@f int
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (' Tu ', cont) from TT where sid=1---spaces (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f 6 ' Glespor '
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go
SELECT * from TT


EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
Go
DECLARE @ptrval binary, @i int,@k int,@f int, @change nvarchar, @newstr nvarchar, @len int
Set @change =n ' sad '--the character to be replaced
--set @len =datalength (@change)
Set @len =len (@change)
Set @newstr =n ' GGG '--Replaced by characters
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (@change, cont) from TT where sid=1---spaces (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f @len @newstr
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go
SELECT * from TT



EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
Go
DECLARE @ptrval binary, @i int,@k int,@f int, @change nvarchar, @newstr nvarchar, @len int
Set @change =n ' Tu '--characters to be replaced
--set @len =datalength (@change)--This can be an error
Set @len =len (@change)
Set @newstr =n ' Glespor '--Replaced by characters
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (@change, cont) from TT where sid=1---spaces (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f @len @newstr
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go
SELECT * from TT

Update TT set cont= ' FD sad FDSA ensemble possibility associate friend Computer Information Technology Co., Ltd. Orange ' where sid=1
Select Datalength (' Tu-wen ')
Select Len (' Tu-wen ')
Select Datalength (' sad ')
Select Len (' sad ')
Select Len (Space (1))


EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
DECLARE @ptrval binary, @i int,@k int,@f int, @change nvarchar, @newstr nvarchar, @len int
Set @change =n ' Tu '--characters to be replaced
--set @len =datalength (@change)--This can be an error
Set @len =len (@change)
Set @newstr =n ' Glespor '--Replaced by characters
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (@change, cont) from TT where sid=1---spaces (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f @len @newstr
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go

EXEC sp_dboption ' pubs ', ' select Into/bulkcopy ', ' true '
DECLARE @ptrval binary, @i int,@k int,@f int, @change nvarchar, @newstr nvarchar, @len int
Set @change =n ' Tu '--characters to be replaced
--set @len =datalength (@change)--This can be an error
Set @len =len (@change)
Set @newstr =n ' Glespor '--Replaced by characters
Select @i=datalength (cont) from TT where sid=1
Set @k=1
While @i>1
Begin
Select @f=charindex (@change, cont) from TT where sid=1---spaces (1)
Set @f=@f-1
SELECT @ptrval = TEXTPTR (cont) from TT WHERE sid=1
If @f>0
UPDATETEXT tt.cont @ptrval @f @len @newstr
If @k=@i
Break
Else
Set @k=@k+1
Continue
End
Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.