Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query and update on Text Field

Status
Not open for further replies.

teamssc

Instructor
Nov 16, 2000
65
US
I'm having a tough time with running a update on a text field and would appreciate anybodies help.

SQL Server 5.0

Thanks

>>>>>>>>>


UPDATE GM2.DBO.ENVIRONMENT
SET (convert(varchar(16),val))='baaaaaaafaaaaaaaaaaaaaaaaaaaaaaacgcaaaaaaaaaaaaahbaaaaaaaaaaaaaaaaaaaaaahbaaaaaacgcaaaaabaaaaaaabaaaaaaaofbaaaaaajbaaaaaeidaaaaamlcaaaaaaa'
WHERE (convert(varchar(16),val))='baaaaaaaeaaaaaaaaaaaaaaaaaaaaaaanadaaaaacfacnakaioaaaaaaaaaaaaaaaaaaaaaaioaaaaaanadaaaaabaaaaaaaaaaaaaaamcbaaaaaagcaaaaacfdaaaaamidaaaaaaa'



 
thank you for the VERY QUICK reply (3am my time).

I'm lost as the update query you reference is very long and I'm not sure of all the syntax I need to rewrite it. Do I have to do all of the declares? Can you help?

Thanks

........................................

declare @otxt varchar(1000)
set @otxt = 'old text'
declare @ntxt varchar(1000)
set @ntxt = 'new text'

declare @txtlen int
set @txtlen = len(@otxt)
declare @ptr binary(16)
declare @pos int
declare @id int
declare curs cursor local fast_forward
for select @id, textptr([field]), charindex(@otxt, [field])-1
from

where [field] like '%' + @otxt +'%'
open curs
fetch next from curs into @id, @ptr, @pos
while @@fetch_status = 0
begin
updatetext
.[field] @ptr @pos @txtlen @ntxt
fetch next from curs into @id, @ptr, @pos
end
close curs
deallocate curs
 
If anyone could help explain the proposed solution or another solution I could use the help.

Also I had a type in the original post as SQL Server 5.0 and that sould have been 2005.
 
Yes you will need most of those declares. Those are used to find the position of the text value within the column, and then update the value with the new value. Look up UPDATETEXT in Books Online, it's got a bunch on info in there as well.

What was the original error that you were getting? I assume it was related to using a text column in a where clause?

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top