Home Forums SQL Server 2008 T-SQL (SS2K8) tsql query - Count the number of spaces in a string RE: tsql query - Count the number of spaces in a string

  • This?

    DECLARE @String VARCHAR(100)

    ,@CharToFind VARCHAR(1)

    SET @String = 'AAAA BBBCB NNNNN NEEEEE ERERERERERE '

    SET @CharToFind = ' '

    SELECT CountOfCharsInTheString = DATALENGTH (@String) - DATALENGTH(REPLACE(@String,@CharToFind,''))