Results 1 to 15 of 15
  1. #1
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104

    Unanswered: update record query

    Hi

    I have a column in a table which has html text. Eg

    Code:
    <p>[Video:-123xyz] <br />A video showing blah blah</p>
    I wish to update the data between the two square brackets within the rest of the text to:

    Code:
    <p>[View:http://www.video123.com/-123xyz] <br />A video showing blah blah</p>
    ...so basically i need to find all occurrences of '[Video:' and replace it with '[View:http://www.video123.com/' .

    Please can someone point me in the right direction?

    cheers

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    you want to use a REPLACE function with a LIKE operator.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    hi

    having a few problems, i'm trying the following:

    Code:
    SELECT REPLACE(
    	SELECT column1 FROM table1, 
    	'Video:', 
    	'View:http://www.video123.com/')
    I know its the second select statement thats not right, but cant find a good enough example of the REPLACE function.... help!

    cheers

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You're missing a vital keyword up there...

    UPDATE

    Code:
    UPDATE myTable
    SET    someColumn = Replace(someColumn, 'Replace this text', 'with this text')
    WHERE  someColumn LIKE '%video:%'
    George
    Home | Blog

  5. #5
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    Hi

    That makes perfect sense, how ever now getting the following error:

    Argument data type ntext is invalid for argument 1 of replace function.

  6. #6
    Join Date
    Mar 2008
    Posts
    6
    Post your exact query...let's take a look-see!

  7. #7
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    Code:
    UPDATE ut_Video
    SET PostBody = Replace(PostBody, 'YouTube:', 'View:http://www.youtube.com/watch?v=')
    WHERE  PostID = 3621
    ....i'm using "PostID = 3621" just to test it before i change the whole table....

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    The code is irrelevent - you can't use replace on text\ ntext. What version SQL Server?

    FYI for future - always mention version of SQL and, if you are doing string manipulation on (n)text coumns, let us know that it is (n)text - normal string functions tend to barf.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Mar 2008
    Posts
    6
    That's an oxymoron isn't it? "The code is irrelevent" - - - you obviously needed the code, to post your response now didn't you?

    Just saying....

  10. #10
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    ok - is there no way to do it then?

    I'm using SQLExpress - SQL Server 9.0.3042

  11. #11
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by SEAQUIL
    That's an oxymoron isn't it? "The code is irrelevent" - - - you obviously needed the code, to post your response now didn't you?

    Just saying....
    Well we know he was using replace. And we know the column he was using on was ntext (from the error message) and we know replace cannot be used on ntext so....

    Wasn't making a big point or having a dig. Trying to point out that there is no way to get replace working with text - you don't need to see the precise syntax to get that.

    Mattock - any reason you are not using NVARCHAR(MAX)?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  12. #12
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    Mattock - any reason you are not using VARCHAR(MAX)?
    ...i didn't design the database - its actually part of a blogging package that was bought off the shelf and i've installed on my server. I guess i could change the column as long as it won't mess anything up?

  13. #13
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    It may do so. It depends on how the application uses the column. You could , perhaps, create a persisted calculated column and use that. The only way, off the top of my head, to force it to VARCHAR(MAX) would be to pass it through a function....

    You've got the source code right? You might want to do some searches on it first to see how it uses this column. If it does not use any text specific string maniplution then it should be ok to change.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  14. #14
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    hi

    Can you see a problem with changing it to VARCHAR, doing the Replace function, then changing it back to nText as i only need to do this replacement once? I'm just worried it may change the data in some way - if not then i think thats the best option rather than leaving it varchar?
    Last edited by mattock; 03-31-08 at 14:20.

  15. #15
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    If it is a one off, maybe try this (or one of the linked solutions in the comments):
    http://www.sqlteam.com/article/searc...-a-text-column

    I haven't used - as such I can't recommend it. Try it on a test system.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •