请问大家一个条件判断如何写?帮帮我

dusttosky 2012-02-04 05:48:03
北京路
北京西路
北京南路
北京小路
南京西路
上海二路
广州河堤路

数据库'地址'字段中有上面数据,我想用一条sql语句筛选出地址字段中的前两位与条件的前2位相同的结果集合.
如: select * from tb where '地址' =SUBSTRING(北京西路,0,3)
得到结果:
北京路
北京西路
北京南路
北京小路

...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangchun1213 2012-02-04
  • 打赏
  • 举报
回复
楼主是啥意思,如一楼和二楼的是否正确
  • 打赏
  • 举报
回复
楼主还不结帖!!!!!!
EnForGrass 2012-02-04
  • 打赏
  • 举报
回复

declare @Tab table (address varchar(10))
insert into @Tab
select '北京路' union all
select '北京西路' union all
select '北京南路' union all
select '北京小路' union all
select '南京西路' union all
select '上海二路' union all
select '广州河堤路'

select * from @Tab where SUBSTRING(address,0,2) =SUBSTRING('北京西路',0,2)
叶子 2012-02-04
  • 打赏
  • 举报
回复

declare @T table (地址 varchar(10))
insert into @T
select '北京路' union all
select '北京西路' union all
select '北京南路' union all
select '北京小路' union all
select '南京西路' union all
select '上海二路' union all
select '广州河堤路'

--是不是这个意思?
declare @p varchar(40)
set @p='北京西路'

select * from @T where left(地址,2)=left(@p,2)

/*
地址
----------
北京路
北京西路
北京南路
北京小路
*/

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧