|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

October 1st, 2005, 07:03 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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, 01:15 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,327
Thanks: 0
Thanked 0 Times in 0 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, 05:26 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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, 01:15 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,327
Thanks: 0
Thanked 0 Times in 0 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, 01:26 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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, 11:06 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Location: Orange County, CA, USA.
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, 03:44 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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, 02:08 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Location: Orange County, CA, USA.
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, 03:49 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
But the data is given to me three times daily from 10 different sources.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |