0

I am currently using this mssql client and I am trying to make 2 queries and passing both results in a function but I can't get the result of my query outside of the scope, even if i use a global variable. I am guessing it is because I only have a reference and I lose it when the function returns? How should I go about this? Here is my code of 1 working query but I am not able to add a 2nd one:

function Query() {
    var err, result, sql = require('mssql'); 

    const connection = new sql.ConnectionPool(config);
    var req = new sql.Request(connection);  
    var queryString = // String of my query //

    connection.connect(function (err) {
        if (err) {
            console.log(err);
            return;
        }
        req.query(queryString, function (err, result){
            if (err) {
                console.log(err);
            }
            else {
                someFunc(result);
            }
            connection.close();
            return;
        });
    });
}

To clarify, I would like to be able to make a 2nd query, combine both results and call someFunc() passing both results. Anyone have an idea how to go about this?

Chsir17
  • 629
  • 1
  • 7
  • 18
  • You can hit multiple queries in single statement, please see already asked question. it could help. https://stackoverflow.com/questions/10797794/multiple-queries-executed-in-java-in-single-statement – Vinit Mehta Jun 05 '18 at 13:14
  • Note: `java != javascript`. Correct me if I am wrong but what has this question to do with java? – L.Spillner Jun 05 '18 at 13:19
  • Oh wow thanks alot! I didnt think I could do it that way! it worked first try and makes this alot easier! – Chsir17 Jun 05 '18 at 13:20
  • Oups yes wrong tag, I definetly wanted to put javascript and not java. It is now corrected – Chsir17 Jun 05 '18 at 13:21

0 Answers0