如何在Node.js中使用'npm mssql'检索多个记录集?

时间:2019-02-11 04:59:46

标签: node.js sql-server express stored-procedures

我有存储过程,该过程返回多个结果,但是当我从npm mssql检索它时,它仅返回第一个结果。

在我的T-SQL脚本中:

   CREATE PROCEDURE usp_myStoreProcedure @param1 varchar(3),@param2 varchar(3) 
   AS
   BEGIN
    select * from firstTable where name=@param1;

    select * from secondTable where name=@param2;

   END

运行此命令时:

   result1: 

       | Name | Subject | Mark|
       |----------------------|
       | Alice|  Maths  | 96  |


   result2: 

       | Name | Subject | Mark|
       |----------------------|
       | Bob  | Science | 93  |

在我的nodejs中,使用npm mssql包

   let conn = await mssql.connect(config);
   let output= await conn
    .request()
    .input("param1", mssql.VarChar(10), "Alcie")
    .input("param2", mssql.VarChar(10), "Bob")
    .execute("usp_myStoreProcedure");
   mssql.close();
   console.log(output);

当前结果:

 {
 "recordsets": 
    [
      [
       {
        "Name": "Alice",
        "Subject":"Maths"
        "Mark": 96
       }
     ],
     [] 
  ],
"recordset": 
    [
      {
        "Name": "Alice",
        "Subject":"Maths"
        "Mark": 96
      }
   ],
"output": {},
"rowsAffected": [1,0],
"returnValue": 0
 }

输出中缺少result2以下:

       | Name | Subject | Mark|
       |----------------------|
       | Bob  | Science | 93  |

0 个答案:

没有答案