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 |
|
paishwarya
Starting Member
4 Posts |
Posted - 2010-11-01 : 12:11:58
|
| I have a name column that has commas between the last n first name and few fields have a comma at the end also. How do I replace the last comma in the string to null. Eg:HERRERA,MARITZA,LOPEZ,DANNYOROURKE,NICHOLAS,I want to remove only if there is a comma at the end of the string. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-01 : 12:18:59
|
| [code]SELECT CASE WHEN RIGHT(Name,1)=',' THEN LEFT(Name,LEN(Name)-1) ELSE Name ENDFROM Table[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
paishwarya
Starting Member
4 Posts |
Posted - 2010-11-01 : 14:33:40
|
| Thanks for your response. But I wanted to do an update on the database to remove this comma. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-02 : 03:30:26
|
| update tableset name=LEFT(Name,LEN(Name)-1) where RIGHT(Name,1)=','MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|