create table Data (Name varchar(50))
insert into Data values ('siva')
insert into Data values ('Ram')
create table data_value(letter varchar(50),value int)
Insert into data_value(letter,value) values('a',1)
Insert into data_value(letter,value) values('i',1)
Insert into data_value(letter,value) values('m',3)
Insert into data_value(letter,value) values('r',2)
Insert into data_value(letter,value) values('s',2)
Insert into data_value(letter,value) values('v',3)
select * from data_value
select * from Data
Select Name , sum(value) as sumvalue
from
(
Select Name,ss.chr, dv.value
from Data
Cross apply (
Select chr From
(
Select top(len(Name)) substring(Name, row_number() over(order by 1/0), 1) as chr
from sys.messages
)A(chr)
)ss
inner join data_value dv on dv.letter = ss.chr
)d group by Name