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
 General SQL Server Forums
 New to SQL Server Programming
 Removing Comma from result

Author  Topic 

jpost
Starting Member

43 Posts

Posted - 2012-09-19 : 13:53:43
I am running a script that will return the first 5 character of a person's last name. The field does hold the entire name of the person, both last, first. If they have a four character last name, a comma appears to separate the field. However this cause me an issue when using it in an external program. Is there a command that I can use that can replace the comma in my results, like a contains? Here is the line of my script, which is apart of a larger one:
select
left(isnull(se.teacherdisplay,'') + space(5),5) as 'Homeroom'
from section se

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-19 : 14:06:16
use replace(field,',',' ') to replace comma to space. if you dont need space use '' instead

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-09-19 : 14:06:34
select left(isnull(replace(se.teacherdisplay,',',''),'') + space(5),5) as 'Homeroom'
from section se
Go to Top of Page

jpost
Starting Member

43 Posts

Posted - 2012-09-19 : 14:24:04
Works perfectly, thanks
Go to Top of Page
   

- Advertisement -