Sunteți pe pagina 1din 4

Please start any new threads on our new site

at http://forums.sqlteam.com . We've got lots


of great SQL Server experts to answer whatever
question you can come up with.
Our new SQL Server Forums are live! Come on
over! We've restricted the ability to create new
threads on these forums.
SQL Server Forums

Username:

Password:

Profile | Active Topics | Members | Search | Forum FAQ


Save Password

Register Now and get your question


answered!

Forgot your Password?

All Forums
SQL Server 2000 Forums
Transact-SQL (2000)
How to replace a comma with a space in a field
Author

Reply to Topic
Printer Friendly

Topic
Posted - 04/05/2007 : 18:28:32

jej1216
Starting Member
27 Posts

We have a field called NAME and the data in it is like this:


'Smith, Joe'
We need to replace the comma with a space so it looks like this:
'Smith Joe'
I know in Oracle I could use TRANSLATE to change the comma
to a space. Is there an equivalent to TRANSLATE in SQL Server
2000?
TIA,
jej1216

Posted - 04/05/2007 : 18:32:53

russell
Pyro-ma-ni-yak

use the Replace function

USA

Replace(name, "," , " ")

5072 Posts

Posted - 04/05/2007 : 18:34:35

sshelper
Posting Yak Master

Instead of using double quotes, use single-quotes:

216 Posts

UPDATE YourTable
SET Name = REPLACE(Name, ',', ' ')
SQL Server Helper
http://www.sql-server-helper.com
Posted - 04/06/2007 : 00:08:14

russell
Pyro-ma-ni-yak

whoaa, correct. good call sshelper. i musta been sleepwalking


lol

USA
5072 Posts

Posted - 04/06/2007 : 10:07:54

jej1216
Starting Member

Great - thanks.

27 Posts

REPLACE is more intuitive than TRANSLATE anyway!


jej1216
Posted - 04/07/2007 : 03:23:55

madhivanan
Premature Yak
Congratulator

quote:
Originally posted by russell

India
22864 Posts

use the Replace function


Replace(name, "," , " ")

I think you have given ACCESS syntax


Madhivanan
Failing to plan is Planning to fail

Posted - 06/22/2007 : 10:41:06

Johnnymarvellous
Starting Member
10 Posts

Hello,
I used the REPLACE example given above for a similar problem
and thank you, I now have no commas in the text, however I
now have a new problem.....
The column in question would apear in the extract file with a
lenght of 50 charaters, however, since using the REPLACE
command, the column is now 500+ characters in length (which
is making a mess for the downstream system)
If I then try to wrap the replace section to try and CAST,
CONVERT or RTRIM, it simply returns an error.
Can anyone tell me:
a. why has the column grown to half a mile in length
b. how can I stop this/shorten the output for this column.
You can probably tell, I'm not that experienced with SQL,
thanks.
JM
Posted - 06/22/2007 : 11:24:24

madhivanan
Premature Yak
Congratulator
India
22864 Posts

Can you post some sample data and the query you used?
How can replacing comma result in increasing the length?
Also post this as new topic to get more replies
Madhivanan
Failing to plan is Planning to fail

Johnnymarvellous
Starting Member
10 Posts

Posted - 06/22/2007 : 12:07:09


quote:
Originally posted by madhivanan
Can you post some sample data and the query you used?
How can replacing comma result in increasing the length?
Also post this as new topic to get more replies
Madhivanan
Failing to plan is Planning to fail

OK, will do thanks

JM

S-ar putea să vă placă și