Hi
I am trying to run a script to extract addresses which fall within a rectangle, as defined by latitude and longitude. To do this I need to be able to compare latitude and longitude values which are stored as nvarchar (don't ask me why) with numeric values in my WHERE statement. I need to remove all non-numeric before I CAST the nvarchar values as numeric so I can do the comparison, so I have stated ISNUMERIC(value) = 1 for both the latitude and longitude. This does not get rid of the conversion error. How can a result set which only contains values where ISNUMERIC(value) = 1 then encounter errors converting the values to numeric???
This is the script I have used so far
SELECT * FROM (SELECT * FROM follow WHERE archive = 140531 AND ISNUMERIC(qas_latitude) = 1 AND ISNUMERIC(qas_longitude) = 1) x WHERE CAST(qas_latitude AS NUMERIC (8,6)) BETWEEN 51.265629 AND 51.659453 AND CAST(qas_longitude AS NUMERIC (8,6)) BETWEEN -0.432238 AND 0.190773
Of the relevant fields, qas_latitude and qas_longitude are both NVARCHAR(20) and can contain NULL.
The error message I am getting is
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to numeric.