use REPLACE with like

  • Hi,

    can i use the REPLACE function with like to accomplish this syntax?(i want to replace all non allowed keywords in file name)

    declare @string nvarchar (max)

    set @string = 'abc?123'

    select REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@string,'\','_'),'/','_'),':','_'),'*','_'),'?','_'),'"','_'),'<','_'),'>','_'),'|','_');

    THX

  • I think you intend to use LIKE to find all instances that have one of the 'invalid' characters and then use the replace sequence to 'fix' the issue. Is that right?

    If so, then this will probably help you: it is called pattern matching.

    select <put your replace sequence here>

    from <your table>

    where <your column> like '%[\/:*?"<>|]%'



    Posting Data Etiquette - Jeff Moden[/url]
    Posting Performance Based Questions - Gail Shaw[/url]
    Hidden RBAR - Jeff Moden[/url]
    Cross Tabs and Pivots - Jeff Moden[/url]
    Catch-all queries - Gail Shaw[/url]


    If you don't have time to do it right, when will you have time to do it over?

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

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