Ever need to know, for example, how many at signs (@) are in a SQL Server column? Here’s a quick trick: Replace the character you’re looking for with the empty string, and compare the new length with the original length. For example:

select mail, len(rtrim(mail))-len(rtrim(replace(mail,’@’,”)))
from (
select ‘none’ as mail union
select ‘on@e’ as mail union
select ‘t@w@o’ as mail) testdata;

Hope this helps someone!

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available