Wednesday, 17 May 2017

Can't store float values to sql server using npm mssql with Node.js

I am trying to do simple UPDATE query and store a percentage value which will go in a percentage column that is of type float in my sql server database.

When I do this:

var percentage = 3.1415;
const updateAttendence = await sql.query `UPDATE Attendence SET percentage = ${ percentage } WHERE session_id =  ${ parseInt( req.body.session ) } AND student_id = ${ parseInt( req.body.AttendanceData[i].id ) } `;

I get this in my database

enter image description here

and when I do this - replace percentage = ${ percentage } with percentage = 3.1415

const updateAttendence = await sql.query `UPDATE Attendence SET percentage = 3.1415 WHERE session_id = 1  AND student_id = 1 ` 

I get what i wanted with percentage = ${ percentage }

enter image description here

I don't get it why its not working as it suppose to. Is it just me or anyone else having this issue and what are the solutions to such a simple thing becoming a problem ( well at least for me ).

-Thanks



via Ahmed.J

No comments:

Post a Comment