Counting Character Instances in a SQL String

I discovered this little trick today. If you’re wanting to count the number of characters present in a given SQL Server varchar variable, or common, use the following convention –assuming a search character contained in the variable @SeekChar –from a variable SELECT LEN(@StringVariableName) – LEN(REPLACE(@StringVariableName,@SeekChar,”)) –from a table field SELECT … Continue reading