SUNAND CH SUNAND CH - 1 year ago 65
SQL Question

How to update a string in middle of it in sql which was repeated twice

If we have a string like below:


I want to remove the second occurrence of '

Please suggest me a sql statement to update this existing string by removing second occurrence of this '//'.

Assume the above string is there in column
, and having unique id associated with it in a row like

doc_id file_path
1 //aaaaa/bbbb/ccccc//ddddd/e/fgh.docx

Answer Source

Use REPLACE function.

Something like:

SELECT '/' + REPLACE(file_path, '//', '/') FROM <table>

It would work in SQL Server. Check for similar function in your RDBMS.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download