To replace exact match in sql server

  • Can anybody tell me how to replace a string with exact match in sql server.

    Ex :

    ' Asset table has primary key named AssetID'

    Here i have to replace word 'Asset' with 'Topic'.

    But REPLACE function replaces both Asset and AssetID

    Thanks in Advance,

    Manohar V

  • There is no way to do like this but you can use sometrick like user space (or some special character) while replacing.

    for example..

    CREATE TABLE Asset(

    AssetId INT,

    AssetName)

    here to replace 'Asset' table name you can use 'Asset(' while replacing.

    Regards,
    Nitin

  • Thanks Nitin,

    But I want to replace all table names inside a procedure with schema prefix to it..

    I have 2000 procedures in my database and i cant prefix manully..

    So I am writing a function to replace the same..

    Here I want to replace with exact match.... Any idea regarding this ...?

  • Then there is no way to do so using T-SQL. You can use managment studio to modify your SPs. Create Script for all SP in single file and use management studio's quick replace option and tick the match whole work option.

    Regards,
    Nitin

  • See also here.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 5 posts - 1 through 4 (of 4 total)

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