How to select a single digit from a MULTI-VALUE field?

60 Views Asked by At

I have the following table with '' as a special character:

Column 1 Column 2
1 13
2 1312
3 315
4 1613
5 15311

I want to select only those records where Column 2 has 3 between special characters. I have used a built-in function of my DB fn_SplitOneValue but it selects 3 and 13 both. Please help!

1

There are 1 best solutions below

2
Gufus On

try this

begin try 
create table #test ([Column 1] int, [Column 2] nvarchar(100))

insert into #test ([Column 1], [Column 2])
values (1, '13')
    ,(2, '1312')
    ,(3, '315')
    ,(4, '1613')
    ,(5, '15311')
end try
begin catch
end catch

select *
from #test
where charindex('3',[column 2],0)>0