sql server r2 2008 - 修剪 [英] sql server r2 2008 - trim

查看:92
本文介绍了sql server r2 2008 - 修剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修剪姓氏和电子邮件地址之间的空格?



目标: 我正在更新 电子邮件地址栏 ,其中包含名字和姓氏以及电子邮件地址。



我能够修改名字和姓氏之间的空格,以便记录为NULL,但不能删除姓氏和电子邮件扩展名之间的空格。



电子邮件地址栏显示为: John.Doe @ xxx.net



需要在LastName和电子邮件扩展名之间取出空格才能显示:John.Doe@xxx.net



我的代码:

UPDATE tbltest

SET [电子邮件地址] = LTRIM((RTRIM(([名字])) +'。'+ [姓氏] +'@ xxx.net'))

WHERE [电子邮件地址] IS NULL



< br $> b $ b



感谢您的时间。

How can I trim the spaces between lastname and email extension?

Goal: I am updating email Address column that is NULL with First and lastname and email extension.

I was able to trim spaces between firstname and last name for the records that is NULL but cannot get rid of the spaces between last name and email extension.

Email Address column is showing as: John.Doe @xxx.net

need to take the spaces out between LastName and email extension to make it to show: John.Doe@xxx.net

My Code:
UPDATE tbltest
SET [Email Address] = LTRIM((RTRIM(([First Name]))+ '.'+[Last Name]+'@xxx.net'))
WHERE [Email Address] IS NULL




Thank you for your time.

推荐答案

使用更新字段REPLACE函数并替换''with''。



UPDATE tbltest SET [电子邮件地址] = REPLACE([电子邮件地址],'','');
Update the field using the REPLACE function and replace ' ' with ''.

UPDATE tbltest SET [Email Address] = REPLACE([Email Address],' ','');


--You can also use LTRIM and RTRIM on the LastName like you did with the FirstName or you can use REPLACE function like Michael showed in solution 1.
UPDATE tbltest
SET [EmailAddress] = LTRIM(RTRIM([FirstName]))+ '.' + LTRIM(RTRIM([LastName])) + '@xxx.net'
WHERE [EmailAddress] IS NULL


这篇关于sql server r2 2008 - 修剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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