0

I want delivery charge compared to subtotal and calculate delivery charges. I got the result successfully. I get query and I put in that code execute in Execute SQL. I got correct answer. But

I have some problem in retrieve data. I got result everytime first position value only .

Below I have mention my code.Give me solution.

String Query ="select ROUND(delivarycharge) from pincodedetails where ROUND(subtotal) <= ( select ROUND(subtotal) from pincodedetails where ROUND(subtotal) >= "+price+" and resturantID="+selArgs+" limit 1) and resturantID ="+selArgs+" and ROUND(subtotal) >= ( select ROUND(subtotal) from pincodedetails where ROUND(subtotal) <= "+price+" and resturantID="+selArgs+" limit 1) order by ROUND(subtotal) LIMIT 1"; 

Database Helper Class:

double deliverycharge= 0; if (mCursor.moveToFirst()) { // Got first result deliverycharge= mCursor.getDouble(0); } return deliverycharge; 

    2 Answers 2

    1

    You should change your code to retrieve to something like:

    Vector<String> temp = new Vector<String>; cursor.moveToFirst(); do { deliverycharge= mCursor.getDouble(0); temp.add() } while (cursor.moveToNext()); return temp; 

    So you will return a vetor containing all Strings.

    10
    • i got only one result sunhari.No need list and all
      – Gomathi
      CommentedMar 19, 2013 at 7:20
    • If you need to retrieve all strings then how can you do without vector or list or String[]? @Gomathi
      – user2185272
      CommentedMar 19, 2013 at 7:21
    • Because every time String will be overwritten @Gomathi
      – user2185272
      CommentedMar 19, 2013 at 7:23
    • I don't need all string value just only one string For example 40 only
      – Gomathi
      CommentedMar 19, 2013 at 7:23
    • And how is that decided? I mean which String do you need? Is it always first column data? @Gomathi
      – user2185272
      CommentedMar 19, 2013 at 7:24
    0

    Try this

    String Query ="select ROUND(delivarycharge) as roundcharge from pincodedetails where ROUND(subtotal) <=( select ROUND(subtotal) from pincodedetails where ROUND(subtotal)>="+price+" and resturantID="+selArgs+" limit 1) and resturantID="+selArgs+" and ROUND(subtotal) >=( select ROUND(subtotal) from pincodedetails where ROUND(subtotal)<="+price+" and resturantID="+selArgs+" limit 1) order by ROUND(subtotal) LIMIT 1"; 

    You need the as "whatever name you want"

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.