如何在sql中的某个字符后修剪所有内容 [英] How to trim everything after certain character in sql

查看:19
本文介绍了如何在sql中的某个字符后修剪所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过删除以@ 开头的所有内容来格式化表格中的电子邮件地址.另外我想用空格替换下划线.

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.

例如:FirstName_LastName@gmail.com

我希望将上述电子邮件更改为:名字姓氏

I would like the above email to be changed like this: FirstName LastName

这是我的代码,但这会修剪@ 之后的所有内容,这就是我想要的.但是我怎样才能用空白替换下划线.我希望使用更新功能在一个语句中进行所有操作.我该怎么做?

Here is my code but this trims everything after the @ and that is what i want. But how can i replace the underscore with blank. I want all in one statement using the update function. How can I do that?

SELECT 
     left (Email, CHARINDEX('@',Email)-1)
  FROM [Dashboard]

感谢您的帮助

推荐答案

SELECT REPLACE(LEFT(Email, CHARINDEX('@',Email)-1),'_',' ')
FROM [DSR].[dbo].[RCA_Dashboard]

这篇关于如何在sql中的某个字符后修剪所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆