p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > SQL Server > SQL Server 2000 > SQL Server 2000
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 1st, 2005, 07:03 PM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 2nd, 2005, 01:15 AM
Friend of Wrox
Points: 4,163, Level: 27
Points: 4,163, Level: 27 Points: 4,163, Level: 27 Points: 4,163, Level: 27
Activity: 11%
Activity: 11% Activity: 11% Activity: 11%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,327
Thanks: 0
Thanked 0 Times in 0 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.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 2nd, 2005, 05:26 AM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 3rd, 2005, 01:15 AM
Friend of Wrox
Points: 4,163, Level: 27
Points: 4,163, Level: 27 Points: 4,163, Level: 27 Points: 4,163, Level: 27
Activity: 11%
Activity: 11% Activity: 11% Activity: 11%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,327
Thanks: 0
Thanked 0 Times in 0 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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old October 5th, 2005, 01:26 PM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old October 7th, 2005, 11:06 PM
Friend of Wrox
Points: 807, Level: 11
Points: 807, Level: 11 Points: 807, Level: 11 Points: 807, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old October 12th, 2005, 03:44 AM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old October 12th, 2005, 02:08 PM
Friend of Wrox
Points: 807, Level: 11
Points: 807, Level: 11 Points: 807, Level: 11 Points: 807, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old October 13th, 2005, 03:49 AM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find (also "find and replace") not working in Visu jayaraj123 Visual Web Developer 2005 4 April 22nd, 2009 06:15 AM
Find&Replace DoctorWho ASP.NET 1.0 and 1.1 Professional 3 June 6th, 2007 10: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



All times are GMT -4. The time now is 11:57 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc