首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求SQL话语,根据字节点找父节点

2013-03-16 
求SQL语句,根据字节点找父节点谢谢![解决办法]select * from tb where 09100101 like 节点+%-- and 节

求SQL语句,根据字节点找父节点


谢谢!

[解决办法]

select * from tb where '09100101' like 节点+'%'-- and 节点<>'09100101'

[解决办法]
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
GO
create table [TB]([col] varchar(8))
insert [TB]
select '09' union all
select '091' union all
select '09100' union all
select '091001' union all
select '09100101'

SELECT distinct b.col from [TB] a
INNER JOIN TB b ON CHARINDEX(a.col,b.COl)=1 AND a.col<>b.col

/*
col
--------
091
09100
091001
09100101

(4 行受影响)


*/

drop table [TB]

热点排行