 <p>Try this:</p> <pre><code>Select area, PARSENAME(userip,4) + '.' + PARSENAME(userip,3) UserIp, COUNT(*) from mytable group by area, PARSENAME(userip,4) + '.' + PARSENAME(userip,3) </code></pre> <p><a href="http://sqlfiddle.com/#!3/06d2f/1" rel="nofollow">SQL DEMO</a></p>