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)
 delete characteres

Author  Topic 

jmanresa
Starting Member

3 Posts

Posted - 2009-06-18 : 06:12:55
Hello I am a rookie.
I need to remove the 'Sr' characters in a field of a table and I do not know how.
I tested with:
SELECT REPLACE (Name, 'Sr','')
FROM ACPR
And generates a view with the modified records as I want, but not updated in the table.
Can I help you? Thanks in advance and best regards.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-18 : 06:24:41
update table
set name=REPLACE(Name, 'Sr','')
where ...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-18 : 06:32:16
My neighbour "Askim Osram" would object to that!
I don't think he likes to be called "Askim Oam".

UPDATE Table1 SET Name = LTRIM(RTRIM(REPLACE(' ' + Name + ' ', ' Sr ', ' ')))



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

jmanresa
Starting Member

3 Posts

Posted - 2009-06-18 : 07:13:15
Thank you very much my dear friend. Perfect and easy
quote:
Originally posted by webfred

update table
set name=REPLACE(Name, 'Sr','')
where ...


No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-18 : 08:37:57
Didn't you see the danger in using the first suggestion, as described in my post?


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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-18 : 08:39:33
quote:
Originally posted by jmanresa

Thank you very much my dear friend. Perfect and easy
quote:
Originally posted by webfred

update table
set name=REPLACE(Name, 'Sr','')
where ...


No, you're never too old to Yak'n'Roll if you're too young to die.




Did you see Peso's reply?

Madhivanan

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

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-18 : 08:51:13
quote:
Originally posted by jmanresa

Thank you very much my dear friend. Perfect and easy
quote:
Originally posted by webfred

update table
set name=REPLACE(Name, 'Sr','')
where ...


No, you're never too old to Yak'n'Roll if you're too young to die.




Not very perfect for all cases
See Peso's correction!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jmanresa
Starting Member

3 Posts

Posted - 2009-06-18 : 09:59:03
Yes you're right. But in this case to remove the characters are 'Sr.' and in this case it is impossible that there is a word that contains Sr.

I will try your solution if I do well there. Thank you very much for your help. Greetings
quote:
Originally posted by Peso

Didn't you see the danger in using the first suggestion, as described in my post?


E 12°55'05.63"
N 56°04'39.26"


Go to Top of Page
   

- Advertisement -