How to trim everything after certain character in sql

前端 未结 2 1577
长情又很酷
长情又很酷 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:19
    SELECT REPLACE(LEFT(Email, CHARINDEX('@',Email)-1),'_',' ')
    FROM [DSR].[dbo].[RCA_Dashboard]
    
    0 讨论(0)
  • 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))));
    
    0 讨论(0)
提交回复
热议问题