1

So I have this query:

SELECT 
   t1.password 
FROM Session AS t1 
INNER JOIN Locations AS t2 ON 
    t2.id = t1.location_id AND 
    SQRT( POWER( CONVERT(t2.longitude,float(10)) - 132.456, 2) + 
        POWER( CONVERT(t2.latitude,float(10)) - 132.456, 2) ) < 100 
WHERE t1.end_distribution = 0 AND t1.end_session = 0

and I get this:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'float(10)) - 132.456, 2) + POWER( CONVERT(t2.latitude,float(10)) - 132.456, 2) )' at line 13

5
  • In MySQL, the syntax for CONVERT is: CONVERT(expression, type); you've got the parameters flip-flopped (reference). Commented Jan 23, 2013 at 22:18
  • still have the same problem(see edit) Commented Jan 23, 2013 at 22:22
  • I would try wrapping the "Convert(exp, type) - #" in parentheses. I don't know enough about mySQL, but based upon the Near it looks like it is expecting a "," after your float and it's finding a "-". Wrapping it in parentheses might appease the order of operation gods. Commented Jan 23, 2013 at 22:25
  • @Love2Learn: The parentheses shouldn't matter. Perhaps float(10) isn't a valid conversion type? Commented Jan 23, 2013 at 22:27
  • i've tried changing it with int.... nothing Commented Jan 23, 2013 at 22:31

2 Answers 2

3

Use

CONVERT(t2.longitude, float(10))

MySQL CONVERT SYNTAX

UPDATE

Depending on documentation above you can't convert expression to type float, use decimal instead.

CONVERT(t2.longitude, decimal(10))
Sign up to request clarification or add additional context in comments.

2 Comments

@user783476 Are you flipped in both places?
thank you very much for the update.. i will test this and get right back at you
0

You've got an invalid specification for the type on the CONVERT function. FLOAT(10) is not valid. It looks like your best alternative will be to use DECIMAL.

From the MySQL Reference Manual: http://dev.mysql.com/doc/refman/5.5/en/cast-functions.html

<snip>

The type for the result can be one of the following values:

BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]

</snip>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.