title: Select distinct first two octets using mssql query
body: <p>Sample Data from my MS SQL table</p>
  
  <pre><code>Column Name: IPAddress
  1.18.120.201,192.178.120.201
  192.168.120.202,192.188.120.202,192.198.120.202
  192.168.121.3
  192.169.121.50
  1.1.1.1
  11.11.11.11
  </code></pre>
  
  <p>AS an output I want</p>
  
  <pre><code>192.168
  192.169
  192.178
  192.188
  192.198
  1.18
  1.1
  11.11
  </code></pre>
  
  <p>The <code>IPAddress</code> column can have multiple ip address values as well.</p>
  
  <p>I have written something like below. Please let me know what changes do i need to make in the query</p>
  
  <pre><code>SELECT
      SUBSTRING(IPAddress, 1, LEN(IPAddress) - CHARINDEX('.',REVERSE(IPAddress))),
      COUNT(*)
  FROM
      ...
  GROUP BY
      SUBSTRING(IPAddress, 1, LEN(IPAddress) - CHARINDEX('.',REVERSE(IPAddress)))
  </code></pre>