Monday, 12 June 2017

node mssql preparestatment output identity id

I'm using https://www.npmjs.com/package/mssql

I'm using sql.PreparedStatement to do the insert and I would like to use the request.output('id', sql.Int) to get my identity id(auto increasing ID). But I'm getting null value.

query:

INSERT INTO queue (refid, name, channel) VALUES (@refid, @name, @channel)

If I use request.output('refid', sql.Int) it was able to get the refid.

If I use OUTPUT INSERTED.id the id will store in recordset as below:

<
  recordsets[[object]],
  recordset[<id:xx>],
  output<refid:123>,
  rowsAdected: [1],
  returnValue: 0
>

What I prefer is:

<
  recordsets[[object]],
  recordset[],
  output<id:999, refid:123>,
  rowsAdected: [1],
  returnValue: 0
>



via hendry91

No comments:

Post a Comment