SDSS error message

Incorrect syntax near '#SELECT'. Arithmetic overflow occurred. Arithmetic overflow occurred.

Your SQL command was:
SELECT
 LTRIM(STR(mjd_r,20,2)) AS MJD,
 dbo.fSDSS(p.objId) AS ID,
 modelMag_g, modelMagErr_g,
 modelMag_r, modelMagErr_r,
 modelMag_i, modelMagErr_i, p.ra, p.dec 
INTO #list
FROM detectionindex d 
 JOIN PhotoObjAll p ON d.objid=p.objid
 JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
SELECT a.*, b.* 
FROM #list a
 CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b





Technical info:
{"ErrorCode":500,"ErrorType":"InternalServerError","ErrorMessage":"Incorrect syntax near '#SELECT'.\r\nArithmetic overflow occurred.\r\nArithmetic overflow occurred.","LogMessageID":"e9db15c7-55ab-4943-9a7f-31cf4e24b218","LogTime":"2018-12-12T16:43:47.3958171-05:00"}