clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1305655 fiddles created (20277 in the last week).

CREATE FUNCTION GetStringCount(@strValue VARCHAR(MAX), @strCount VARCHAR(MAX)) RETURNS INT AS BEGIN RETURN ISNULL((DATALENGTH(@strValue) - DATALENGTH(REPLACE(@strValue COLLATE Latin1_General_CS_AS, @strCount, ''))) / DATALENGTH(@strCount), 0); END
 hidden batch(es)


CREATE TABLE example ( col VARCHAR(MAX) ); INSERT INTO example VALUES ('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'), ('At vero eos et accusam et justo duo dolores et ea rebum.'), ('Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'), (NULL);
4 rows affected
 hidden batch(es)


SELECT dbo.GetStringCount('Hello', 'l'); SELECT dbo.GetStringCount('This costs 5$.', '$'); SELECT dbo.GetStringCount('This costs 5€.', '€');
(No column name)
2
(No column name)
1
(No column name)
1
 hidden batch(es)


SELECT *, dbo.GetStringCount(col, 'a') FROM example;
col (No column name)
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 11
At vero eos et accusam et justo duo dolores et ea rebum. 3
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 8
0
 hidden batch(es)