Printer Friendly Version Print this thread
Email this thread to a friend eMail this thread to a friend
Featured Web Site Template

Hundreds More at Free Site Templates.com!

Web Site Partners
Sponsored Links
Jet City Software
 
Whos Here ?
There are 0 guests and 1 members in the forums right now.
Reflects user activity within the last 5 minutes
Moderator(s): Prowler, jcokos
Member Message

jshenricks
Joined: Oct 07, 2003
# Posts: 7

View the profile for jshenricks Send jshenricks a private message

Posted: 2003-Oct-10 04:45
Edit Message Delete Message Reply to this message

Hi all,

In SQL, is it possible to update records using wildcards? I've tried this with the SET command, but I can't get it to work.

Here's what I'm trying:

UPDATE table
SET column = '%value_1%'
WHERE table.column LIKE '%value_2%'

For some reason the wildcard character won't work for the "SET" command. However, I AM able to find records that match the "WHERE" command using wildcard characters.

Any ideas?

Thanks,

Jeremy Henricks



NEntropy
Joined: Dec 08, 1999
# Posts: 1117

View the profile for NEntropy Send NEntropy a private message

Posted: 2003-Oct-10 06:45
Edit Message Delete Message Reply to this message

How could you do wildcard updates?

What are you trying to do? Are you trying to match a certain value within a string and update with another value, all throughout the table? Wildcard really has no meaning in updates...



jshenricks
Joined: Oct 07, 2003
# Posts: 7

View the profile for jshenricks Send jshenricks a private message

Posted: 2003-Oct-10 06:56
Edit Message Delete Message Reply to this message

Yes, what you mentioned is exactly what I want to do. For example, I want to update a value when it matches my query.

Such as, replace "domain1" in http://www.domain1.com/ with "domain2" for all records. I need to update only the domain name, because the folder structure after the domain may be different for each record.



rjzak
Joined: Eons Ago
# Posts: 57

View the profile for rjzak Send rjzak a private message

Posted: 2003-Oct-10 14:35
Edit Message Delete Message Reply to this message

The wildcard in the SET command is what is causing the problems. Instead, you should list the whole string...

UPDATE table
SET column = 'http://www.domain2.com/'
WHERE table.column LIKE '%domain1%'

Or, if you have a lot of differnt URLs, like http://www.domain1.com/page1.html & http://www.domain1.com/page2.html, then you may need to read the values from the table first, and parse the string to replace the domain part and then do your updates.



NEntropy
Joined: Dec 08, 1999
# Posts: 1117

View the profile for NEntropy Send NEntropy a private message

Posted: 2003-Oct-10 21:22
Edit Message Delete Message Reply to this message

As rjzak says, you'll have to do it manually. There is no easy way of updating data like that just using SQL...





livesocket
Joined: Sep 23, 2008
# Posts: 1

View the profile for livesocket Send livesocket a private message

Posted: 2008-Sep-23 15:54
Edit Message Delete Message Reply to this message

update <tablename> set <columnname>=REPLACE(<columnname>, '<old value>', '<new value>') WHERE <columnname> LIKE '<old value>%'


You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
  1. You have not yet logged in, or registered properly as a member
  2. You are a member, but no longer have posting rights.
  3. This is a private forum, for which you do not have permissions.

If you are a recent member, it's possible that you simply have not yet confirmed your account. Please check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions contained within.

If you cannot find this message, click here to Re-Send it.

If you are still experiencing problem, please read the Login Assistance Article for some advice on what may be causing your login not to work properly.

Switch to Advanced Editor and ... Create a New Topic or Reply to this Thread

New posts Forum is locked
© 1995  ·  iWeb, Inc  ·  DBA JimWorld Productions