title: SQL Server 403 Error When Setting a Geography Type for Update
body: <p>All I need to do is simply get one geography value from a table and store it in another table. There is some logic for which row to take from the origin table so it's not just a straight select.</p>
  
  <p>In any of 50 possible variants of this, I get this error when hitting the update to the target table:</p>
  
  <blockquote>
    <p>Msg 403, Level 16, State 1, Line 1<br>
    Invalid operator for data type. Operator equals not equal to, type equals geography.</p>
  </blockquote>
  
  <p>My SQL looks like this at the moment:</p>
  
  <pre><code>declare 
      @EquipmentId int
      , @CurrentLocationId int
      , @CurrentGeoLocation geography
      , @LastUpdated datetime
  
  select @EquipmentId = 
  (
      select top 1 EquipmentId
      from Equipment
      order by EquipmentId
  )
  
  select @CurrentLocationId = (select top 1 EquipmentLocationId from EquipmentLocation where EquipmentId = @EquipmentId order by LastUpdated desc)
  
  select @LastUpdated = (select top 1 LastUpdated from EquipmentLocation where EquipmentId = @EquipmentId order by LastUpdated desc)
  
  UPDATE
      dbo.Equipment
  SET
      CurrentLocationDateTime = @LastUpdated
      , CurrentGeoLocation = (select GeoLocation from EquipmentLocation where EquipmentLocationId = @CurrentLocationId)
      , ModifiedBy = 'system'
      , ModifiedByUserId = -1
      , ModifiedDate = getdate()
  WHERE
      EquipmentId = @EquipmentId
  </code></pre>
  
  <p>I have had <code>CurrentGeoLocation</code> set in a variable of the same type, selected into by the same statement you see in the update.</p>
  
  <p>I have had an <code>@CurrentGeoLocation</code> variable populated by a <code>geography::STGeomFromText</code> as well as <code>geography::Point()</code> function call.</p>
  
  <p>I've used <code>Lat</code> and <code>Long</code> variables to call <code>Point</code> and <code>FromText</code> functions.</p>
  
  <p>All the same result, the above 403 error. I could understand it somewhat when I was concatenating various permutations of the <code>GeomFromText</code> function that needs well known text format for the point parameter, but field value to field value is killing me, as is the fact that I get this error no matter how I try to give the origin point data to the target table.</p>
  
  <p>Thoughts?</p>
  
  <p>Update:
  I've been experimenting a little and found that the following works just fine:</p>
  
  <pre><code>declare @GL geography
  
  select @GL = (select GeoLocation from EquipmentLocation where EquipmentLocationId = 25482766)
  
  print convert(varchar, @GL.Lat)
  print convert(varchar, @GL.Long)
  
  update Equipment set CurrentGeoLocation = geography::Point(@GL.Lat, @GL.Long, 4326)-- @NewGL where EquipmentId = 10518
  </code></pre>
  
  <p>But then when I apply this plan to the original script, I'm back to the same error.</p>
  
  <p>The data in the test is working off the exact same records as in the original script. The original script is working off a collection of EquipmentIds, on the first one, I encounter this problem. The short test script uses the same EquipmentLocationId and EquipemntId that are the selected values used to update the first Equipment record in my collection.</p>