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":"a3c6ad65-5c51-4767-9467-04f90243ca5b","LogTime":"2019-08-24T07:54:58.5951925-04:00"}