0

So the title may not be the most helpful.. but I am using Microsoft Azure to call a stored procedure

mssql.query("EXEC allInfo ?", [meetingID],  
    {
        success: function(results1) {            
            console.log(results1);

            var endOutput2 = request.body.meetingName;

            response.send(statusCodes.OK, endOutput2 ); 
      },
      error: function(err) {
            console.log("error is: " + err);
            response.send(statusCodes.OK, { message : err });
      }
    });

I know the line

var endOutput2 = request.body.meetingName; 

is not correct. I am trying to get the result from executing the stored procedure allInfo. How can I get the data so I can parse it and use it later in the project. The stored procedure is below.

BEGIN

SELECT * FROM ScheduleMe.main_Meeting 
WHERE meetingID = @meetingID;

SELECT * FROM ScheduleMe.date_Time
WHERE meetingID = @meetingID;

END

I can get it to output like this(below) but I cannot then just grab meetingName or other variables.

[{"meetingID":"899c-64b7-fa94","meetingName":"Test 1","meetingDescription":"test","meetingLength":30,"meetingNotes":null,"hostUserID":"[email protected]"}]

1 Answer 1

1

You can get the result from the result1 variable.

In order to get the first meetingName returned you can do

results1[0].meetingName

Although it's best to check if the array returned has any elements so this will work better

var endOutput2 = null;
if (results1.length)
    endOutput2  = results1[0].meetingName
Sign up to request clarification or add additional context in comments.

6 Comments

THANK YOU, I had tried results1.meetingName but it didnt work, adding the [0] worked!
Keep in mind that if more than one meeting is returned, this will only return the first one.
I also want to get it from the second SELECT statement. Here is the output. I want to get the date/time from both [ { meetingID: '899c-64b7-fa94', meetingDateTime: { Wed, 01 Apr 2015 04:00:00 GMT nanosecondsDelta: 0 }, setDateTime: false }, { meetingID: '899c-64b7-fa94', meetingDateTime: { Wed, 01 Apr 2015 04:30:00 GMT nanosecondsDelta: 0 }, setDateTime: false } ]
You should familiarize yourself with arrays and objects in JavaScript. In the case of getting the meetingDateTime from the second element, you can do results1[1].meetingDateTime.
Here is more info about arrays in JavaScript and objects
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.