如何按一个顺序排列记录。 [英] How to arrange the records in one sequence.

查看:89
本文介绍了如何按一个顺序排列记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多存储在SQL Server 2012中的记录列表,其中包含一些以12开头的记录。 (12)我想删除数字并希望直接启动喜欢这是XYZ。



我怎么能? />


我尝试了什么:



目前我通过制作手动制作数据库中的更改。

I have huge list of records stored in the SQL Server 2012 which consist of some record starting with 12). and some starting with (12. I want to remove number and want to make it starting directly Like "hi this is XYZ".

How can i ??

What I have tried:

Currently i am making it manually by making changes in the database.

推荐答案

更新A

SET A.Name =

CASE

WHEN LEFT(B.Name,3)= '12。'然后RTRIM(LTRIM(更换(B.NAME,LEFT(B.Name,3),'')))

WHEN LEFT(B.Name,2)='12'那么RTRIM(LTRIM(替换(B.NAME,LEFT(B.Name,2),'')))



ELSE B.Name

END



来自TableName A

INNER JOIN TableName B

ON A.PK_ID = B.PK_ID
UPDATE A
SET A.Name =
CASE
WHEN LEFT(B.Name, 3) = '12.' THEN RTRIM(LTRIM(REPLACE(B.NAME, LEFT(B.Name, 3), '')))
WHEN LEFT(B.Name, 2) = '12' THEN RTRIM(LTRIM(REPLACE(B.NAME, LEFT(B.Name, 2), '')))

ELSE B.Name
END

FROM TableName A
INNER JOIN TableName B
ON A.PK_ID = B.PK_ID


您可以使用REPLACE()来清理它。



如果您只想以不同方式显示它,您可以执行以下操作:

You can use REPLACE() to clean it up.

If you only want to display it differently you can do something like:
SELECT REPLACE(REPLACE(field1, '12).', ''), '(12.', '') -- replace strings with blanks
FROM table1 
ORDER BY  REPLACE(REPLACE(field1, '12).', ''), '(12.', '') 





你可以用同样的方式更新



You can update it the same way

UPDATE table1 SET field1 = REPLACE(REPLACE(field1, '12).', ''), '(12.', '') -- replace strings with blanks


这篇关于如何按一个顺序排列记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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