Solved

Query Replace Help

Posted on 2011-03-10
7
241 Views
Last Modified: 2012-05-11
I'm trying to do a replace on a filed that has many different options.

filedname = post, table = posts

[url=http://domain.com/blah.flv]blah video[/url]
[url=http://domain.com/video/name.mp4]name of him[/url]
[url=http://domain.com/video/2001/funny.flv]funny clip[/url]

Open in new window


I want to update these to make them look like:

[media]http://domain.com/blah.flv[/media]
[media]http://domain.com/video/name.mp4[/media]
[media]http://domain.com/video/2001/funny.flv[/media]

Open in new window

0
Comment
Question by:N R
  • 4
  • 2
7 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35097401
update table
set fieldname = REPLACE(fieldname, '')

update table
set fieldname =REPLACE(fieldname, '
', '[/media]')
0
 
LVL 11

Author Comment

by:N R
ID: 35097418
can you put all that in code tags so I can see it,  the url tags disappeared haha.
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35097426
Here
update table
set fieldname = REPLACE(fieldname, '')

update table
set fieldname =REPLACE(fieldname, '', '[/media]')

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35097430
Not that, let me redo
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35097446
Here is the correct one
update table
set fieldname = REPLACE(fieldname, '[url=', '[media]')

update table
set fieldname =REPLACE(fieldname, '[/url]', '[/media]')

Open in new window

0
 
LVL 11

Author Comment

by:N R
ID: 35097469
Well, that still doesn't get me there that will make the result set be:
[media]http://domain.com/blah.flv]blah video[/media]
[media]http://domain.com/video/name.mp4]name of him[/media]
[media]http://domain.com/video/2001/funny.flv]funny clip[/media]

Open in new window


but what I need is:
[media]http://domain.com/blah.flv[/media]
[media]http://domain.com/video/name.mp4[/media]
[media]http://domain.com/video/2001/funny.flv[/media]

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35097472
How about this?
update posts set post = '[media]' + SUBSTRING(post, charindex('=', post) + 1, charindex(']', post, 2) - charindex('=', post) - 1) + '[/media]'

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question