开发者

Remove single characters in sql records?

I'm working on importing some files and I noticed that some of the email addresses are prefixed wit开发者_如何学运维h a comma. Eg: ,abc@abc.com

In a table with 1500 emails, I've found that 700+ of these have this issue. How would I update them so that the comma is removed?


UPDATE dbo.Table
  SET Email = STUFF(Email, 1, 1, '')
  WHERE Email LIKE ',%';


try:

UPDATE YourTable
    SET YourColumn=RIGHT(YourColumn,LEN(YourColumn)-1)
    WHERE LEFT(YourColumn,1)=','


If you know they always start with a ,:

UPDATE SomeTable
SET SomeColumn = SUBSTRING(SomeColumn, 2, 4000)
WHERE SomeColumn LIKE ',%';

Otherwise you could do this to get rid of all , no matter where they appear. Note that here adding a WHERE SomeColumn LIKE '%,%' clause might adversely affect performance.

UPDATE SomeTable
SET SomeColumn = REPLACE(SomeColumn, ',', '');


UPDATE table SET email = SUBSTRING(email, 2, 1000) WHERE email LIKE ",%";

The % is a wildcard, so this will only match those fields that start with a comma.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜