Monday, 17 April 2017

Splitting a var into another var that contains only numbers

Currently I'm getting my data out of a SQL Server 2012 using a powershell and the mssql plugin. I'm trying to extract out data using queries, so I had a query to get the particular information and then use express.js to send the data over to a textbox. This is the code currently.

Server.JS

app.get('/Warning', function (req, res) {

var sql = require("mssql");

// config for your database
var config = {
    user: 'Atiqah',
    password: 'password',
    server: 'DESKTOP-5045H9Q', 
    database: 'TestDB'
};

// connect to your database
sql.connect(config, function (err) {
    var record;
    if (err) console.log(err);

    // create Request object
    var request = new sql.Request();
    var stringrequest = 

    // query to the database and get the records
    request.query("SELECT COUNT([EntryType]),EntryType FROM TestTable GROUP BY EntryType", function (err, recordset) {

        if (err) console.log(err)


        // send records as a response
        record = recordset;
        console.log("You are currently connected to " + JSON.stringify(config));
        res.send(JSON.stringify(recordset));
        //console.log("Query submitted is " + JSON.stringify(stringrequest));

    });
});

Index2.html

    function myFunction() {
    $.get("/Warning", function (string) {
        $('#txtWarning').val(string);
    });
}
<body onload="myFunction()">
<textarea rows="8" cols="70" id="txtWarning"></textarea></body>

The data that i get out of the textbox would be something like this:

{"recordsets":[[{"":734,"EntryType":"\"Warning\""},{"":1049,"EntryType":"\"Error\""}]],"recordset":[{"":734,"EntryType":"\"Warning\""},{"":1049,"EntryType":"\"Error\""}],"output":{},"rowsAffected":[2]}

How do I go around only getting the numbers out of this var? Any help would be much appreciated. The output that I wanted would look something like this. 734, 1049, 734, 1049.



via Aslah Fida'iyi

No comments:

Post a Comment