ra.shinde, you are correct, the while loop will never end. Besides from your first function you can derive the word count as well. See code below:
-- Number of specific Characters
Declare @aa varchar(100)
Set @aa = 'SQL Server 2005 Atif Sheikh A'
Select Len(@aa) - Len(Replace(@aa, ' ', '')) + 1