Wrox Programmer Forums
|
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
 
Old October 1st, 2005, 06:03 PM
Authorized User
 
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old October 2nd, 2005, 12:15 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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.



 
Old October 2nd, 2005, 04:26 AM
Authorized User
 
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old October 3rd, 2005, 12:15 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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.

 
Old October 5th, 2005, 12:26 PM
Authorized User
 
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could I reference another table of illegal characters? How would I integrate this?

 
Old October 7th, 2005, 10:06 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 12th, 2005, 02:44 AM
Authorized User
 
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old October 12th, 2005, 01:08 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 13th, 2005, 02:49 AM
Authorized User
 
Join Date: Jun 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But the data is given to me three times daily from 10 different sources.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find&Replace DoctorWho ASP.NET 1.0 and 1.1 Professional 3 June 6th, 2007 09:40 AM
Find and Replace 2 characters at once!! HELP scovitch65 VB.NET 2002/2003 Basics 2 March 18th, 2006 01:40 AM
find and replace code zabsmarty General .NET 0 March 15th, 2006 10:39 PM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.