0

I am writing an android application in which i have to get a range of values like the below,

I have a DB in which the contents are like the below 5 columns,

_ID | _NAME | _AGE | _HEIGHT | _WEIGHT |

1   | aabv  | 10   | 5.0     | 30

1   | babs  | 10   | 5.1     | 28

1   | cabg  | 10   | 5.2     | 29

1   | dabs  | 10   | 5.3     | 32

1   | eaba  | 10   | 5.0     | 31

1   | gabe  | 10   | 5.0     | 31

1   | iabr  | 10   | 5.0     | 31

1   | xabt  | 10   | 5.0     | 31

1   | zabu  | 10   | 5.0     | 31

now i would like to extract the rows which are 'd' to 's' => output should => dabs, eaba, gabe, iabr

Can i do it so? if so what is the sql query.

I tried the below - "request the name which are in between D and S"

mCursor = mDb.query(DATABASE_NAME, new String[] { _ID, _NAME, _AGE, _HEIGHT, _WEIGHT }, 
                _NAME + " BETWEEN " + "D" + " AND " + "S", 
                null,
                null, 
                null, 
                _NAME + " ASC");

Its giving an error saying there is an error in the statement =>

_NAME + " BETWEEN " + "A" + " AND " + "S"

Kindly help.

[1/11] Q: In the above table if i want to extract multiple data from a column say, i would like to extract where _HEIGHT = (5.1,5.2,5.3) How i should add the query?

Vamsi
  • 5,853
  • 6
  • 29
  • 36

1 Answers1

0

As they are text and not numbers, you need to encapsulate them in quotes in your query string.

_NAME + " BETWEEN " + "'A'" + " AND " + "'S'"
Barak
  • 16,318
  • 9
  • 52
  • 84
  • Absolute!! Thanks!! missed the detail :) – Vamsi Dec 14 '12 at 14:39
  • 1
    Do it like this: `_NAME + " BETWEEN " + "\"A\"" + " AND " + "\"S\""` – Leandros Dec 14 '12 at 14:39
  • Which one is better and why? -Both worked for me atleast!! programming for android – Vamsi Dec 14 '12 at 14:46
  • With the above solution, its not giving the names starting with 'S', Also if some name starts with some Numerical what would be the query! can you kindly tell me what is the problem – Vamsi Dec 17 '12 at 04:30
  • Because you are telling it between a and s. So it stop at S. If you have a name that is just "S" you will see it included in your selection. You might want to change it to "Szzzz"... that oughta catch everything. :P – Barak Dec 17 '12 at 04:57
  • Thanks Barak, you are just awesome!! – Vamsi Dec 17 '12 at 05:07