title: How can I adapt my radius search by postcode/zipcode to radius search by town?
body: <p>We currently have a working script to return a list of all our products within a radius of a postcode/zipcode. It searches for all products that have locations in area codes within the <em>@miles</em> parameter of <em>@lookingfor</em> postcode, also returning the distance.</p>
  
  <p>The <em>PostodeLocation</em> table contains four columns: the town/city, the postcode (pcd) and the Northing (grn) and Easting (gre) grid references. The primary key is on the postcode.</p>
  
  <p>The problem is: I do not know the centre centre of each town or the postcodes for the outer radius of each town. I cannot adapt the script to give me all products in locations within a radius of a town, or even a town centre.</p>
  
  <p>Has anybody else encountered this requirement and found a solution? I'm looking for a technique more than the actual code requirement.</p>
  
  <p>Current script:</p>
  
  <pre><code>declare @lookingfor nvarchar(10) = 'sw1a 1aa'
  declare @miles int = 5
  DECLARE @UserCoordX bigint
  DECLARE @UserCoordY bigint
  SELECT    @UserCoordX = GRE
          , @UserCoordY = GRN
  FROM MyCompany.dbo.PostcodeLocations pcls
  WHERE pcls.PCD = @lookingfor
  select pcls.PCD
      , p.ProdName
      , sqrt((((pcls.GRE - @UserCoordX) * (pcls.GRE - @UserCoordX)) + ((pcls.GRN - @UserCoordY) * (pcls.GRN - @UserCoordY)))/(160.9334*160.9334)) as Distance
  from MyCompany.dbo.pcls_disk pcls
  inner join MyCompany.dbo.Loc l on l.Postcode = pcls.pcd
  inner join MyCompany.dbo.X_ProdLoc xpl on xpl.LocId = l.LocId
  inner join MyCompany.dbo.Prod p on p.ProdId = xpl.ProdId
  where p.StatusId = 4 and p.HideFromSearch = 0
  and ((pcls.GRE - @UserCoordX) * (pcls.GRE - @UserCoordX)) + ((pcls.GRN - @UserCoordY) * (pcls.GRN - @UserCoordY)) 
          &lt;= cast(@Miles * 160.9334 * @Miles * 160.9334 as bigint)
  order by [Distance]
  </code></pre>