Results 1 to 4 of 4

Thread: [RESOLVED] How to replace portion of string in field in table

  1. #1
    Hyperactive Member
    Join Date
    Mar 08
    Posts
    393

    Resolved [RESOLVED] How to replace portion of string in field in table

    Hello: I have a table that has a field called attachFilename

    currently, all the records are poulated for this field with a string such as "\\companydrive\g-drive\company_TEST\Job_12\Job_12.dwg"

    and I need to replace this portion of the string: "\\companydrive\g-drive\company_TEST" with a different string.

    Is there an easy way to do this with sql?

    I'm using sql express 2008.

    thanks,
    Proctor

  2. #2
    Frenzied Member
    Join Date
    Sep 02
    Location
    Columbus, Ohio
    Posts
    1,808

    Re: How to replace portion of string in field in table

    Look into REPLACE

    select replace('\\companydrive\g-drive\company_TEST\Job_12\Job_12.dwg','Company_TEST','with this')

  3. #3
    Frenzied Member
    Join Date
    Sep 02
    Location
    Columbus, Ohio
    Posts
    1,808

    Re: How to replace portion of string in field in table

    Here is a better example:

    Code:
    create table #VBForums(MyText Varchar(200))
    
    insert into #VBForums(mytext) values('\\companydrive\g-drive\company_TEST\Job_12\Job_12.dwg')
    
    Update #VBForums
    set MyText = replace('\\companydrive\g-drive\company_TEST\Job_12\Job_12.dwg','Company_TEST','with this')
    where myText = '\\companydrive\g-drive\company_TEST\Job_12\Job_12.dwg'
    
    select * from #VBForums
    
    drop table #VBForums

  4. #4
    Hyperactive Member
    Join Date
    Mar 08
    Posts
    393

    Re: How to replace portion of string in field in table

    That's awesome!! Thanks .......

    Proctor

Posting Permissions

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