 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 1st, 2005, 06:03 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Find and replace?
Is there a way you can find and replace words in sql? I need to replace certain chars within a couple of columns, !"£$%^&*()_+ etc and spaces with an underscore _
so for example, es.c0408.010 with es_c0408_010
Any help, as always is greatly received.
Stuart
|
|

October 2nd, 2005, 12:15 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
See the Replace funtion in BOL:
this will replace a '.' with an '_':
REPLACE ( <Column> , '.', '_')
You can use it within and Update statement or select statement.
|
|

October 2nd, 2005, 04:26 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is great, Thanks
update tbl_product_import
set [new sku] = REPLACE ( [new sku] , '.', '_')
where [new sku] like '%.%'
Is there a way though that I could amend this to replace !"£$% aswell in the same pass? kinda like an or/and?
|
|

October 3rd, 2005, 12:15 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
You do not need the where clause in your select statement. It will only replace if the char(s) exist in that column. And, I belive you will need to run a separate UPDATE for each character you want to replace.
|
|

October 5th, 2005, 12:26 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Could I reference another table of illegal characters? How would I integrate this?
|
|

October 7th, 2005, 10:06 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
problem with referencing a table of "illegal" characters is how would you populate them. I suggest storing the ascii value of illegal characters and use sql to convert/compare them if thats the direction you want to go.
|
|

October 12th, 2005, 02:44 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I set each character in turn into a dts package like the one above, only there are 35,000 product codes which could potiential have an 'illegal' character, maybe even two! It would seem each dts sql script time outs out and doesn't do anything. :-(
update tbl_product_import
set [new sku] = REPLACE ( [sku] , '.', '_')
Any ideas on a better method?
Stuart
|
|

October 12th, 2005, 01:08 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can "fix" the data with either DTS or sql code. I prefer SQL code but thats me. The real solution is to prevent the bad data from being loaded in the first place. This should best be done on the source system. I am more of a backend developer so I prefer the back end tools over things like DTS.
|
|

October 13th, 2005, 02:49 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
But the data is given to me three times daily from 10 different sources.
|
|
 |