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 2000 Forums
 Transact-SQL (2000)
 select REPLACE two chars in one field

Author  Topic 

jej1216
Starting Member

27 Posts

Posted - 2008-10-17 : 14:34:39
I need to select employee names from a table. I am finding that names may have a comma (Joe Smith, Jr) or an apostrophe (Frank O'Neil).

I know I can use this to get rid of one of the characters:

SELECT
COMPANY
,EMPLID
,CONVERT(CHAR(30),(REPLACE(NAME,',',' '))) AS NAME
FROM EE_TBL
etc.

I need to replace the apostrophe as well - all in the same select.

My attempts to repeat REPLACE on the same field errors out:
CONVERT(CHAR(30),(REPLACE(NAME,',',' ')),(REPLACE(NAME,'''',' '))) AS NAME
Argument data type varchar is invalid for argument 3 of convert function.

Is there a way to replace two characters in the same field during a select? I need to replace the comma and the apostrophe with spaces.

TIA,

jej1216


hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-17 : 17:08:32
[CODE]REPLACE(REPLACE(NAME,',',''),'''','')[/CODE]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-18 : 02:56:33
Refer this to understand how single quotes are treated in sql server
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

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

- Advertisement -