现在有1数据表A 表中有1字段 地址。。现在添加了个城市,要将 地址中 有出现 ‘市’的 数据,吧包含市的节选出来 放到城市里。
如: 地址:A市B路C号 将A市提取出来 放到 城市 如果没有出现市 就不理会 要NULL 或者不处理
求具体SQL语句 。。。
只要将如何删选出地址的数据即可。。SELECT (求补充) as 城市 FROM 表1
------解决方案--------------------
--> 测试数据: @T
declare @T table (地址 varchar(9))
insert into @T
select 'A市B路C号' union all
select 'C路D号' union all
select 'B市B路D号'
select
left(地址,charindex('市',地址)) as 城市
from @T
where charindex('市',地址)>0
/*
城市
---------
A市
B市
*/
------解决方案--------------------
LS +1
有样学样select
case when charindex('市',地址)>0
then left(地址,charindex('市',地址))
else null
end
from table