我有一列Emails
。在该列中有电子邮件地址,以一些数字结尾。我想删除那些尾随数字。
示例:
jjj@yahoo.com234
lhf@hotmail.com1984
lll@gmail.com567
结果:
jjj@yahoo.com
lhf@hotmail.com
lll@gmail.com
非常感谢。
答案 0 :(得分:0)
检查以下内容:
DECLARE @DATA VARCHAR(32)
SET @DATA = 'jjj1@yahoo.com234'
SELECT REPLACE(@DATA, SUBSTRING(SUBSTRING(@DATA, CHARINDEX('@', @DATA) + 1, LEN(@DATA)), PATINDEX('%[0-9]%', SUBSTRING(@DATA, CHARINDEX('@', @DATA) + 1, LEN(@DATA))), LEN(SUBSTRING(@DATA, CHARINDEX('@', @DATA) + 1, LEN(@DATA)))), '') AS DATA
+================+
| DATA |
+================+
| jjj1@yahoo.com |
+----------------+
更新查询:
UPDATE dbo.Email
SET
Email = REPLACE(Email, SUBSTRING(SUBSTRING(Email, CHARINDEX('@', Email)+1, LEN(Email)), PATINDEX('%[0-9]%', SUBSTRING(Email, CHARINDEX('@', Email)+1, LEN(Email))), LEN(SUBSTRING(Email, CHARINDEX('@', Email)+1, LEN(Email)))), '');
答案 1 :(得分:0)
你可以尝试这个解决方案,我多次使用它。
从给定代码创建一个函数。
UPDATE [dbo].[Email]
SET Email = AA.Email
FROM [dbo].[Email] AEL
CROSS APPLY
(SELECT TOP 1 [dbo].[RemoveSpecialChars](Email)AS Email FROM [dbo].[Email] at WHERE at.Email=AEL.Email) AA
然后你可以使用下面的查询
给出的这个功能<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXXX-1', 'auto');
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '1234', // Transaction ID. Required.
'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
});
ga('ecommerce:addItem', {
'id': '1234', // Transaction ID. Required.
'name': 'Fluffy Pink Bunnies', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': 'Party Toys', // Category or variation.
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
});
ga('ecommerce:send');
</script>