Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 25th, 2004, 11:12 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Query- Please help!

Hello,

I am trying to write a SQL query that would update email address on a field. The filed is text format and contains several email addresses in a field. I just want to update one address among them and keep the rest as is. Could you please provide me feedback regarding writing a script for this? I would highly appreciate it.

The query will be run against SQL server DB.

Thanks in advance for your help.

Reply With Quote
  #2 (permalink)  
Old October 25th, 2004, 11:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this.
Code:
Update TABLENAME set EMAILCOL = Replace(EMAILCOL,'oldEmailAddress','NewEmailAddress') where PRIMARYKEYCOL = ItsValue
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #3 (permalink)  
Old October 25th, 2004, 12:06 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply. This doesn’t seem to work as the field is text format as oppose to varChar.

I get this message:

[Microsoft][ODBC SQL Server Driver][SQL Server]Argument data type text is invalid for argument 1 of replace function.

Reply With Quote
  #4 (permalink)  
Old October 25th, 2004, 09:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, for text datatypes Replace, wouldn't work. There is a workaround for this.
Code:
Declare @val varchar(8000)
Select @val=EMAILCOL from TABLENAME where PRIMARYKEYCOL = ItsValue
-- select @val
update TABLENAME set EMAILCOL = replace(@val,'oldval','newval') where PRIMARYKEYCOL = ItsValue
Select EMAILCOL from TABLENAME where PRIMARYKEYCOL = ItsValue
This would work only if the length of that column doesn't exceed 8000 characters. I would suggest you not to use text for that column. Check what is the maximum length of that column? If that is not more than 8000, you may change that to varchar(8000) in the table structure. Assuming a MailId doesn't exceed 40 characters at the maximum, does that column contain more that 200 EMail Ids? If that is going to be less than that, you can blindly modify its datatype to be varchar(8000 or less)

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query i need seearam MySQL 7 November 30th, 2008 03:14 AM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
SQL Query!! dpkbahuguna Beginning VB 6 5 October 12th, 2007 12:39 AM
Help with SQL query sattaluri Access 2 August 11th, 2006 09:26 AM
SQL query PinkyCat Classic ASP Databases 3 March 11th, 2005 01:41 PM



All times are GMT -4. The time now is 01:08 PM.


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