javascript - node mssql update query, get rowcount -


i'm using nodejs package mssql (https://npmjs.org/package/mssql#cfg-node-tds) connect ms sql database , perform update queries.

i understand if update query ends not affecting rows, still return success event. handle success event differently if 0 rows affected since not intended outcome of query.

after doing research, found when performing sql queries, can use @@rowcount number of affected rows, i've yet figure out how use mssql node package.

has used node package , and handled update queries way trying to?

thanks!

okay, right link provided, node package can call stored procedures.

either create logic on js side or tsql side.

since dba/developer trade, lets create sp perform update return number of rows effected.

i using adventure works sample database.

-- use sample db use adventureworks2012; go  -- sample select select *  [person].[person] lastname = 'walters'; go  -- stored procedure create procedure usp_update_first_name (@id int, @first varchar(50)) begin     update [person].[person]     set [firstname] = @first     [businessentityid] = @id;     return(@@rowcount); end go  -- make call declare @ret int; exec @ret = usp_update_first_name @id = 4, @first = 'robert'; print @ret; 

this call returns following output.

(1 row(s) affected) 1

in js code, action if @ret = 0 or action b if @ret > 0.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -