dm98101
asked on
How to retrieve and edit text placed in ntext field in MSSQL ????????????? please help
How to retrieve and edit text placed in ntext field in MSSQL ????????????? please help
I m using MSSQL 2000 SP3 and only what I can see in when i retrieve all data from table in SQL enterpirise manager is " <long text> how to retrive content from that field and change it...... PLease help me??????
I m using MSSQL 2000 SP3 and only what I can see in when i retrieve all data from table in SQL enterpirise manager is " <long text> how to retrive content from that field and change it...... PLease help me??????
ASKER
how to write that code on this:
table name is: log_sampladata
text field name I want to edit and change data is named: SampleData
Type of field SampleData is: ntext (16)
Please help me¨.......
table name is: log_sampladata
text field name I want to edit and change data is named: SampleData
Type of field SampleData is: ntext (16)
Please help me¨.......
--drop table log_sampladata
CREATE TABLE log_sampladata (i int identity(1,1), SampleData text)
INSERT INTO log_sampladata SELECT REPLICATE('a',32)
DECLARE @txtPtr Varbinary(16)
SELECT @txtPtr = TEXTPTR(SampleData)
FROM log_sampladata
WHERE i = 1
--note the initial length
SELECT DATALENGTH(SampleData)
FROM log_sampladata
WHERE i =1
UPDATETEXT log_sampladata.SampleData @txtPtr NULL 0 ' bbbb '
--check the length to c whether updated
SELECT DATALENGTH(SampleData)
FROM log_sampladata
WHERE i =1
readtext log_sampladata.SampleData @txtPtr 1 0
CREATE TABLE log_sampladata (i int identity(1,1), SampleData text)
INSERT INTO log_sampladata SELECT REPLICATE('a',32)
DECLARE @txtPtr Varbinary(16)
SELECT @txtPtr = TEXTPTR(SampleData)
FROM log_sampladata
WHERE i = 1
--note the initial length
SELECT DATALENGTH(SampleData)
FROM log_sampladata
WHERE i =1
UPDATETEXT log_sampladata.SampleData @txtPtr NULL 0 ' bbbb '
--check the length to c whether updated
SELECT DATALENGTH(SampleData)
FROM log_sampladata
WHERE i =1
readtext log_sampladata.SampleData @txtPtr 1 0
ASKER
If I drop it I ll loose data right?
yes of course, That code is a sample , i want to check whether it is working or not, for that only i put it...
ASKER
ok i wait
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
USE pubs
GO
DECLARE @ptrval varbinary(16)
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr INNER JOIN publishers p
ON pr.pub_id = p.pub_id
AND p.pub_name = 'New Moon Books'
READTEXT pub_info.pr_info @ptrval 1 25
GO
Use WriteText or UPDATETEXT to Edit the text fields refer BOL for more details
This example puts the text pointer into the local variable @ptrval, and then WRITETEXT places the new text string into the row pointed to by @ptrval.
USE pubs
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'
GO
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
AND p.pub_name = 'New Moon Books'
WRITETEXT pub_info.pr_info @ptrval 'New Moon Books (NMB) has just released another top ten publication. With the latest publication this makes NMB the hottest new publisher of the year!'
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'
GO