user1281959
user1281959

Reputation:

Count right word from a specific variable

How should I be able to count the word "asdf" in the variable aaa with value "asdf_dd_adf34asdf_sdf"?

DECLARE @aaa varchar;

SET @aaa = 'asdf_dd_adf34asdf_sdf';

Upvotes: 0

Views: 169

Answers (1)

Guffa
Guffa

Reputation: 700800

Count how many characters goes away if you remove the occurances of the word, and divide by the length of the word:

(len(aaa) - len(replace(aaa, 'asdf', ''))) / len('asdf')

Upvotes: 3

Related Questions