sql server - NodeJS, Checking for Null from MSSQL, and Bug with Output Parms -


two questions regarding stored proc , nodejs code below: 1) why showing null?

if set value this: request.output('studentid', sql.int, 0); 0 instead of null; doesn't seem changing output parameter.

2) how test int null in node js? wanted

   if (studentid = mysqlnull) {       validuserpass = 'n';     }     else (        validuserpass = 'y';     } 

mssql stored proc:

create procedure [dbo].[usp_validatestudentuserpass2] (      @userid varchar( 32 ),      @password varchar( 12 ),      @studentid int output  )  -- return studentid if user/password correct   select @studentid = student_id students       student_userid = @userid      , student_password = @password  

sql test cases:

declare @studentid2 int; exec usp_validatestudentuserpass2 'jhill', 'hjk123', @studentid2 out select @studentid2 studentidshouldbe31

declare @studentid2b int; exec usp_validatestudentuserpass2 'jhill', 'hjkxxx', @studentid2b out select @studentid2b studentidshouldbenull

test results:

enter image description here

nodejs

// config database var config = {     user: 'readonlyuser1',     password: 'whatever',     server: 'localhost\\sqlexpress',      database: 'studentsold'  };  // test user/pass rows in table  var login = {        user: 'jhill',        password: 'hjk123' };  console.log(login.user + ' ' + login.password);   const sql = require('mssql'); var getstudentid = function() {   var conn = new sql.connectionpool(config);   conn.connect().then(function(conn) {     var request = new sql.request(conn);     request.input('userid', sql.varchar(32), login.user);     request.input('password', sql.varchar(12), login.password);     request.output('studentid', sql.int);     request.execute('usp_validatestudentuserpass2').then(function(err, recordsets, returnvalue, affected) {       var studentid = request.parameters.studentid.value;        console.log('studentid=' + studentid);      }).catch(function(err) {       console.log('catch err' + err);     });   }); }  getstudentid(); 

nodejs output:

jhill hjk123 studentid=null ^c 


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -