SQL Replace function - without hardcoding

  • Hi Team,

    using below query to raplace the string values (REPLACE abc with T1223), how to use the query without hard coding.

    i want to store the values in another temp table and access in main query.

    'abc', 'T1223',

    'def', 'T456',

    'ghi', 'T789',

    'jkl', 'T1011',

    'mno', 'T12'

    --

    select id,name,

    LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(name,

    'abc', 'T1223'),

    'def', 'T456'),

    'ghi', 'T789'),

    'jkl', 'T1011'),

    'mno', 'T12'))) New_id

    from TAB

  • Please don't post multiple threads for the same problem. You'll only divide the help you would receive and confuse people on the version that you're using.

    Further replies in here:

    http://www.sqlservercentral.com/Forums/Topic1688498-3077-1.aspx

    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
  • Minnu (5/25/2015)


    Hi Team,

    using below query to raplace the string values (REPLACE abc with T1223), how to use the query without hard coding.

    i want to store the values in another temp table and access in main query.

    'abc', 'T1223',

    'def', 'T456',

    'ghi', 'T789',

    'jkl', 'T1011',

    'mno', 'T12'

    --

    select id,name,

    LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(name,

    'abc', 'T1223'),

    'def', 'T456'),

    'ghi', 'T789'),

    'jkl', 'T1011'),

    'mno', 'T12'))) New_id

    from TAB

    Again, your request is a bit difficult to understand because you've not provided the necessary test data or DDL. Please see the your other post which appears to be a near duplicate to this one.

    http://www.sqlservercentral.com/Forums/Topic1688465-3077-1.aspx

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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