SQLite3-从地址字符串中提取街道名称

时间:2019-06-06 10:28:41

标签: sql sqlite

我在SQLite3中有一个表,其列为“地址”,如

row1: "bakerstr 42, city" 
row2: "bakerstr 22, zip"
row3: "poststr 42a, location"
row4: "Maple drive"

如何从地址栏中仅提取街道名

预期结果:

bakerstr
poststr 
Maple drive

1 个答案:

答案 0 :(得分:0)

尝试一下:

declare @t table (address varchar(50))

insert into @t values ('bakerstr 42, city')
insert into @t values ('poststr 42a, location')
insert into @t values ('Maple drive')


select substring(address,1,case when PATINDEX('%[0-9]%',address) = 0 then len (address) else PATINDEX('%[0-9]%',address)-2 end)  from @t