Update rows

  • Hi,

    I have table with column values as below. I need to change the folder name from QA to PROD. Please advise.

    C:\QA\Documents\pdf1

    C:\QA\Documents\pdf2

    C:\QA\Documents\pdf3

    C:\QA\Documents\pdf4

    C:\QA\Documents\pdf5

    .

    .

    .

    and I need to change the path as below:

    C:\PROD\Documents\pdf1

    C:\PROD\Documents\pdf2

    C:\PROD\Documents\pdf3

    C:\PROD\Documents\pdf4

    C:\PROD\Documents\pdf5

    .

    .

    .

  • Something like this, I imagine:

    UPDATEYourTable

    SET[YourPathname] = REPLACE([YourPathname] , '\QA\' , '\PROD\' )

    - Adam

  • Here are two options:

    CREATE TABLE Fun_Test( Somepath nvarchar( 50 ));

    INSERT INTO Fun_Test

    VALUES

    ( 'C:\QA\Documents\pdf1' ),

    ( 'C:\QA\Documents\pdf2' ),

    ( 'C:\QA\Documents\pdf3' ),

    ( 'C:\QA\Documents\pdf4' ),

    ( 'C:\QA\Documents\pdf5' );

    SELECT Somepath,

    REPLACE( Somepath, 'C:\QA\', 'C:\PROD\' ),

    STUFF( Somepath, 4, 2, 'PROD' )

    FROM Fun_Test;

    GO

    DROP TABLE Fun_Test;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply