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 2005 Forums
 Transact-SQL (2005)
 replace

Author  Topic 

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-07-20 : 07:11:50
Hi I need to replace a text field called "desc" with itself minus the last four characters.
Somebody has run a process which puts a rude word on the end of the decsriptions

thanks ps its sql server 2000

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-20 : 07:15:37
[code]update t
set desc = left(t.desc, len(t.desc) - 4)
from yourtable t
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-07-20 : 07:23:48
Sorry it's a memo field - i forgot to say

Server: Msg 8116, Level 16, State 2, Line 1
Argument data type text is invalid for argument 1 of len function.
Server: Msg 8116, Level 16, State 1, Line 1
Argument data type text is invalid for argument 1 of left function.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-20 : 07:27:22
Replace LEN with DATALENGTH.
And use SUBSTRING instead of LEN.

SUBSTRING(Col1, 1, DATALENGTH(Col1) - 4)




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-07-20 : 07:40:20
thanks a lot
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-20 : 08:05:30
quote:
Originally posted by Peso

And use SUBSTRING instead of LEN.
And use SUBSTRING instead of LEFT.


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -