When I execute this query the following error is displayed.
[Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to float.]
I am wondering that the error is in the comparison part that is fb_userevents.userid = '100002917025417' when this long string within the single quot is replaced by 1 or 0 it works. Instead of quote (') around it why it tries to convert into float??
I am using SQL Server 2005
select
fb_event.eventname
from
fb_event
inner join
fb_userevents on fb_userevents.eventid = fb_event.eventid
where
fb_userevents.userid = '100002917025417'
and DATEDIFF(hh,fb_event.startdate,getdate()) < 0
and acos(sin(0) * sin(convert(float,altitude)) +
cos(0) * cos(convert(float,altitude)) *
cos(convert(float,longitude) - 101)) * 6371 <= 1000
The altitutes and longitutes of that user:

altitudeorlongitudeuseridisvarcharand they are passing a string to it so there should be no numeric casting going on there at all in that bit. Clearly the values being returned when thewhereclause is changed are just different and not valid numbers.