Re: [SQL ] 字段内的文字值重新排序

楼主: SangoDragon (SANGO)   2016-06-16 20:25:09
http://i.imgur.com/t91Mo3W.jpg
create table #a
(address char(30))
GO
insert #a
VALUES ('01X02Y03Z'),
('2341X666Y806Z')
GO
SELECT ADDRESS,
SUBSTRING ( ADDRESS,1,CHARINDEX('X',ADDRESS) ),
SUBSTRING ( ADDRESS,CHARINDEX('X',ADDRESS)+1,CHARINDEX('Y',ADDRESS) -
CHARINDEX('X',ADDRESS)),
SUBSTRING ( ADDRESS,CHARINDEX('Y',ADDRESS)+1,CHARINDEX('Z',ADDRESS) -
CHARINDEX('Y',ADDRESS)),
SUBSTRING ( ADDRESS,CHARINDEX('Y',ADDRESS)+1,CHARINDEX('Z',ADDRESS) -
CHARINDEX('Y',ADDRESS))+
SUBSTRING ( ADDRESS,CHARINDEX('X',ADDRESS)+1,CHARINDEX('Y',ADDRESS) -
CHARINDEX('X',ADDRESS))+
SUBSTRING ( ADDRESS,1,CHARINDEX('X',ADDRESS) )
FROM #A
※ 引述《SangoDragon (SANGO)》之铭言:
: 数据库名称: MS SQL
: 数据库版本: SQL 2008
: 住址的值要重新排序
: 例如: Table: Employee
: 字段: Address 改成 Address1
:
作者: LZN (秋)   2016-06-17 10:12:00
可能要小心spiltter重复出现在address内的问题*splitter

Links booklink

Contact Us: admin [ a t ] ucptt.com