select TW.ClientCode,tw.word - sequence column here from next bit of sql
from Tblwords TW
where clientcode='54553002'
group by TW.ClientCode, TW.ClientCode,tw.word
declare
@string varchar(1000)='OCEAN' this would become tw.word
select
(
select
cast(ascii(substring(@string,N,1)) as varchar(5))+','
from
[dictionary].[dbo].[fnTally]() nr
where
nr.N<=len(@string)
FOR XML PATH('')
) as ascii_seq
declare @string varchar(1000)='OCEAN' this would become tw.word
select @string = tw.word
from Tblwords TW
where clientcode='54553002'
group by TW.ClientCode,tw.word
select
(
select
cast(ascii(substring(@string,N,1)) as varchar(5))+','
from
[dictionary].[dbo].[fnTally]() nr
where
nr.N<=len(@string)
FOR XML PATH('')
) as ascii_seq
select tw.word, scr
from Tblwords TW
CROSS APPLY
(
SELECT
scr FROM
(
select
cast(ascii(substring(tw.word,N,1)) as varchar(5))+',' scr
from
[dictionary].[dbo].[fnTally]() nr
where
nr.N<=len(tw.word)
FOR XML PATH('')
)ascii_seq
)t
where clientcode='54553002'
group by TW.ClientCode,scr,tw.word
select tw.word, scr
from Tblwords TW
CROSS APPLY
(
select
cast(ascii(substring(tw.word,N,1)) as varchar(5))+',' scr
from
[dictionary].[dbo].[fnTally]() nr
where
nr.N<=len(tw.word)
FOR XML PATH('')
)y
where clientcode='54553002'
group by TW.ClientCode,scr,tw.word
select TW.ClientCode,tw.word,
STUFF
((
select
cast(ascii(substring(tw.word,N,1)) as varchar(5))+','
from
[dictionary].[dbo].[fnTally]() nr
where
nr.N<=len(tw.word)
FOR XML PATH('')
) ,1,2,'')
AS cusr
from Tblwords TW
where clientcode='54553002'
group by TW.ClientCode,tw.word
use Dictionary
select
cast(ascii(substring('OCEAN',N,1)) as varchar(5))+','
from
[dictionary].[dbo].[fnTally]() nr
where
nr.N<=len('OCEAN')
FOR XML PATH('')