Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 APPENDING TEXT FIELD

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2005-10-12 : 18:47:42
Hi friends
i want to append data a text field .how can i do that plz.
any sample code much appreciated.
actually am reading text file and updating a text field.
i managed to read the file and having problem with updating text field.
Thanks for your help

Cheers

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2005-10-12 : 20:16:30
ok finally i managed to do it.
using UPDATETEXT function.if anyone interested following is my code

CREATE PROC usp_Read_Update_template_with_text
(@filename sysname ,@templateId int)
/*
@templateId is pkey of the template table to update
eg:- exec usp_Read_Update_template_with_text 'c:\nmptests\rtfintotx.rtf',1
*/
as
BEGIN
declare @text varchar(8000),@ptr VARBINARY (16)
SET nocount ON
--read text file first
CREATE TABLE #tempf (line varchar(8000))
EXEC ('bulk INSERT #tempf FROM "' + @filename + '"')
--SELECT * FROM #tempf

--now updated Template table
DECLARE text_cursor CURSOR FORWARD_ONLY FOR SELECT * FROM #tempf
OPEN text_cursor
FETCH NEXT FROM text_cursor INTO @text
---now loop thru the cursor
WHILE @@FETCH_STATUS = 0
BEGIN
--we cant use updated statemet here as we want to append to the field
select @ptr=TEXTPTR (rtfdata) FROM template WHERE templateid=@templateId
--now append to the text.(here @prt points to which record to update)
UPDATETEXT template.rtfdata @ptr null null @text
FETCH NEXT FROM text_cursor INTO @text
END

DROP TABLE #tempf --get rid of it
--release resources
CLOSE text_cursor
DEALLOCATE text_cursor

END
GO



Cheers
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-13 : 01:37:41
Refer these also
http://www.mindsdoor.net/SQLTsql/InsertTextData.html
http://www.mindsdoor.net/SQLTsql/ReplaceText.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -