在SQL Server 2008
declare @longAddress varchar(max)
set @longAddress = 'District ALBERT numero 1234 city CASABLANCA région de NORTH country MOROOCO '
--assuming regin follow city
select CHARINDEX('numero',@longAddress)-- this is how you get position of numero and region
--do a substring
select SUBSTRING(@longAddress,1,CHARINDEX('numero',@longAddress)-1) -- get the district
select SUBSTRING(@longAddress,charindex('city',@longAddress),charindex('région',@longAddress)-charindex('city',@longAddress)) -- get the city
--combine
select SUBSTRING(@longAddress,1,CHARINDEX('numero',@longAddress)-1) -- get the district
+SUBSTRING(@longAddress,charindex('city',@longAddress),charindex('région',@longAddress)-charindex('city',@longAddress)) -- get the city
以相同的模式始終是地址? 'District numero city ....' –
是Jorge。區和市 – aziz