Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:14:57+00:00 2026-06-17T22:14:57+00:00

I have a mobile app for which I am using Azure Mobile Services as

  • 0

I have a mobile app for which I am using Azure Mobile Services as a backend. I have a scenario in which I need to modify the elements that the client is requesting from the database. I need to compute the rank and percentile of the record being requested, based on its best score and the best scores of all other records in the table. I followed the example here and wrote the below script:

function read(query, user, request) {
    request.execute({
        success: function(results) {
            results.forEach(function(item) {
                var totalsql = "SELECT COUNT(*) FROM scoreInfo";
                mssql.query(totalsql, {
                    success: function(totalresults) {
                        var totalCount = totalresults[0].Column0;

                        var moresql = "SELECT COUNT(*) FROM scoreInfo WHERE bestscore > ?";      
                        mssql.query(moresql, [item.bestscore], {
                            success: function(moreresults) {
                                var moreBestCount = moreresults[0].Column0;

                                item.bestrank = moreBestCount + 1;
                                item.bestpercentile = 100 - moreBestCount*100/(totalCount+1);                                
                            }
                        });
                    }
                });
            });
            request.respond();
        }
    });
}

But I don’t see the results as expected on the client side. I even tried logging the results on the server side but what I see on the client side doesn’t match what is logged. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:14:59+00:00Added an answer on June 17, 2026 at 10:14 pm

    The problem here is that the mssql.query function is asynchronous. What ends up happening is that in the forEach loop you’re firing many asynchronous mssql requests, and right after that (without waiting for them to complete) you’re callng request.respond(); At that time you still don’t have any of the responses (remember that node.js is single-threaded, so none of the responses have arrived yet).

    What you’ll need to do is to delay calling request.respond() until all the responses to the mssql calls have arrived. The code below shows one way of doing that.

    function read(query, user, request) {
        request.execute({
            success: function(results) {
                var updateResult = function(index) {
                    if (index >= results.length) {
                        // all done
                        request.respond();
                    } else {
                        var item = results[index];
                        var totalsql = "SELECT COUNT(*) FROM scoreInfo";
                        mssql.query(totalsql, {
                            success: function(totalresults) {
                                var totalCount = totalresults[0].Column0;
    
                                var moresql = "SELECT COUNT(*) FROM scoreInfo WHERE bestscore > ?";
                                mssql.query(moresql, [item.bestscore], {
                                    success: function(moreresults) {
                                        var moreBestCount = moreresults[0].Column0;
    
                                        item.bestrank = moreBestCount + 1;
                                        item.bestpercentile = 100 - moreBestCount*100/(totalCount+1);
    
                                        updateResult(index + 1); // update next result
                                    }
                                });
                            }
                        });
                    }
                }
    
                updateResult(0);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mobile app that is using LinqToDatasets to update/insert into a SQL
I have a mobile app webservice client that connects to a WCF webservice(on my
I'm using Windows Azure Mobile services to upload pictures from a mobile app. The
I have inherited a half-finished mobile app built using Backbone.js (which I have never
I have a windows mobile app (mymobiler) that i am trying to install and
I have to make a mobile app that calculates the real life size of
I have some strange scrolling problems with my PhoneGap (using jQuery Mobile) app: I'm
I'm working on mobile (Android/iOS) app, which will integrate with FB and have a
I am working in a Mobile project (using Titanium Studio), in which i have
I have a jQuery Mobile web app which targets iOS and Android devices. A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.