Sql server 如何使用SQL Server从col1中保存的长地址中提取短地址
如何从保存在我的Sql server 如何使用SQL Server从col1中保存的长地址中提取短地址,sql-server,string,extract,long-integer,Sql Server,String,Extract,Long Integer,如何从保存在我的col1到col2中的长地址中提取短地址?问题是我想要地区和城市的名字 我的长地址示例: District ALBERT numero 1234 city CASABLANCA région de NORTH country MOROOCO . 我想知道我的简短地址: District ALBERT city CASABLANCA 我需要帮助我在我的col1中有很多注册,我不能手动注册 很抱歉,我的英语在sql server 2008中测试不好 declare @longA
col1
到col2
中的长地址中提取短地址?问题是我想要地区和城市的名字
我的长地址示例:
District ALBERT numero 1234 city CASABLANCA région de NORTH country MOROOCO .
我想知道我的简短地址:
District ALBERT city CASABLANCA
我需要帮助我在我的col1
中有很多注册,我不能手动注册
很抱歉,我的英语在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
在SQLServer2008中测试
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
您可以使用:
update yourTable
set col2 = substring(col1,1,(charindex(col1,'numero')-1)
+ substring(col1,
(charindex(col1,'city'),
((charindex(col1,'région')-1)-charindex(col1,'city')))
您可以使用:
update yourTable
set col2 = substring(col1,1,(charindex(col1,'numero')-1)
+ substring(col1,
(charindex(col1,'city'),
((charindex(col1,'région')-1)-charindex(col1,'city')))
地址是否总是采用相同的模式<代码>区号城市……是豪尔赫。地区和城市地址是否总是以相同的模式<代码>区号城市……是豪尔赫。地区和城市腐蚀研究所并没有密切关注结果。我会修改非常感谢chungtinhlakho它的工作非常好的解决方案谢谢。对不起,没有仔细查看结果。我将非常感谢chungtinhlakho的工作完美的解决方案谢谢。非常感谢Jorge这是我的工作。谢谢你非常感谢Jorge那对我来说很有用。非常感谢。