create table tester (ID int identity(1,1), val varchar(15))
declare @loopcnt int
set @loopcnt = 1
while @loopcnt < 101
begin
insert into tester
select 'Alex' + convert(varchar(3), @loopcnt)
union all select 'Qmoto'+ convert(varchar(3), @loopcnt)
union all select 'Sven'+ convert(varchar(3), @loopcnt)
union all select 'Scott'+ convert(varchar(3), @loopcnt)
union all select 'Steven'+ convert(varchar(3), @loopcnt)
union all select 'Alan'+ convert(varchar(3), @loopcnt)
union all select 'Bart'+ convert(varchar(3), @loopcnt)
union all select 'Bjorn'+ convert(varchar(3), @loopcnt)
union all select 'Chris'+ convert(varchar(3), @loopcnt)
union all select 'Barry'+ convert(varchar(3), @loopcnt)
union all select 'Asthma'+ convert(varchar(3), @loopcnt)
union all select 'SQL'+ convert(varchar(3), @loopcnt)
union all select 'Word'+ convert(varchar(3), @loopcnt)
union all select 'I'+ convert(varchar(3), @loopcnt)
union all select 'Think'+ convert(varchar(3), @loopcnt)
union all select 'This'+ convert(varchar(3), @loopcnt)
union all select 'is'+ convert(varchar(3), @loopcnt)
union all select 'enough'+ convert(varchar(3), @loopcnt)
union all select 'B'+ convert(varchar(3), @loopcnt)
set @loopcnt = @loopcnt + 1
end
alter table tester add mytestval as left(val, 1)
create clustered index idx_tester on tester (mytestval)
go
create table tester2 (ID int identity(1,1), val varchar(15) primary key clustered)
insert into tester2
select 'S'
union all select 'B'
---end creating test data
select a.* from tester a inner join tester2 b on left(a.val, 1) = b.val
select a.* from tester a inner join tester2 b on substring(a.val, 1, 1) = b.val
select a.* from tester a inner join tester2 b on cast(a.val as char(1)) = b.val
select a.* from tester a inner join tester2 b on a.mytestval = b.val
drop table tester
drop table tester2