How to trim everything after certain character in sql

前端 未结 2 1599
长情又很酷
长情又很酷 2021-01-12 02:25

I am trying to format the email address in my table by removing everything starting the @. Also I would like to replace the underscore with blank space.

For exampl

2条回答
  •  感动是毒
    2021-01-12 03:23

    This can be helpful if you need to remove all after the last certain character:

    Declare @String nvarchar(max) = 
      'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\log.ldf'
    
    
    select reverse(substring(reverse (@String), CHARINDEX('\', reverse (@String))+1, len(reverse (@String))));
    

提交回复
热议问题