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.
| Author |
Topic |
|
rajani
Constraint Violating Yak Guru
367 Posts |
Posted - 2005-10-12 : 18:47:42
|
| Hi friendsi 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 helpCheers |
|
|
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 codeCREATE PROC usp_Read_Update_template_with_text(@filename sysname ,@templateId int)/*@templateId is pkey of the template table to updateeg:- 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_cursorEND GO Cheers |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|