tsql - Need to count specific letters from a search, why does it show as zero? the data is formatted as ntext -
i trying count occurrence of letter 'a' on column named description, using query below getting result of zero.
select description, ( datalength(description) - datalength(replace(cast(description nvarchar(max)), 'a', '')) ) /datalength(description) [a]
from categories
an int divided int return int. notice *1.0
example
declare @description nvarchar(max)='cat in hat never seen' select @description, (( datalength(@description) - datalength(replace(cast(@description nvarchar(max)), 'a', '')) )*100) / datalength(@description) [a]
returns
(no column name) cat in hat never seen 10
Comments
Post a Comment