日期:2014-05-17 浏览次数:20603 次
declare @str nvarchar(100)
set @str='KD01.0003.0002'
select count(id) from #temp where charindex(@str,codes)>0
--> 测试数据:[table1]
if object_id('[table1]') is not null drop table [table1]
GO
create table [table1]([codes] varchar(24))
insert [table1]
select 'KD01' union all
select 'KD01.0003' union all
select 'KD01.0003.0001' union all
select 'KD01.0003.0001.0001' union all
select 'KD01.0003.0001.0001.0001' union all
select 'KD01.0003.0001.0001.0002' union all
select 'KD01.0003.0001.0001.0003' union all
select 'KD01.0003.0001.0002' union all
select 'KD01.0003.0001.0003' union all
select 'KD01.0003.0001.0003.0001' union all
select 'KD01.0003.0001.0003.0003' union all
select 'KD01.0003.0001.0003.0004' union all
select 'KD01.0003.0001.0003.0005' union all
select 'KD01.0003.0001.0003.0007' union all
select 'KD01.0003.0001.0003.0009' union all
select 'KD01.0003.0001.0003.0010' union all
select 'KD01.0003.0001.0003.0012' union all
select 'KD01.0003.0001.0004' union all
select 'KD01.0003.0001.0005' union all
select 'KD01.0003.0001.0006' union all
select 'KD01.0003.0002' union all
select 'KD01.0003.0002.0001' union all
select 'KD01.0003.0002.0002' union all
select 'KD01.0003.0002.0002.0001' union all
select 'KD01.0003.0002.0002.0003' union all
select 'KD01.0003.0002.0002.0004' union all
select 'KD01.0003.0002.0002.0005' union all
select 'KD01.0003.0002.0003' union all
select 'KD01.0003.0002.0003.0001' union all
select 'KD01.0003.0002.0003.0002'
select * from [table1] t
CROSS APPLY
&nb