1

I am using node-mssql package from npm to connect my MSSQL server. My code looks like

const sql = require("mssql"); 
var sqlconnectionpool = new sql.ConnectionPool(...mydbconfig);

sqlconnectionpool.connect().then(pool => {
  const myquery = "select 1 ,2 as 'two',3 ,4";
  pool
    .request()
    .query(myquery)
    .then(result => {
      console.log(JSON.stringify(result.recordset.toTable()));
    })
    .then(res => {
      pool.close();
    });
});

as a result, i was expecting

{
    columns: [
        { name: "", nullable: false },
        { name: "two", nullable: false },
        { name: "", nullable: false },
        { name: "", nullable: false }
    ],
    rows: [[1, 2, 3, 4]]
};

instead i am getting

{
    columns: [{ name: "", nullable: false }, { name: "two", nullable: false }],
    rows: [[[1, 3, 4], 2]]
}

Results are automatically grouped by column names. In my case, I have column name for only one column. Since they are getting grouped by column names, the results are not in same order.

Could someone clarify how to achieve the desired result (for the above query, the numbers in same order as they are requested)?

I am using node v 8.9.4 and mssql driver 4.1.0

Sriram
  • 767
  • 2
  • 17
  • 42

0 Answers0