Error with sql Like

5

How do I extract all fields beginning with '1.' from the database? In my statement I used LIKE but it did not have any return, but if I remove the point it already returns something, but it returns fields that I do not want, eg 10.1; What's wrong.

SELECT * FROM tbCelula WHERE C_Numeracao LIKE '1.%';
tbCelula
C_id     C_Numeracao
1        1.1
2        10.1
3        1.1.1
4        2.1

Return 1.1; 1.1.1

    
asked by anonymous 02.12.2015 / 11:02

1 answer

3

You can use SubString :

SELECT * FROM tbCelula WHERE SUBSTRING(C_Numeracao FROM 1 FOR 1) = 1

Depending on the case you need to do a CAST in SubString by passing it to Integer, it's easy to do anyway!

SELECT * FROM tbCelula WHERE CAST(SUBSTRING(C_Numeracao FROM 1 FOR 1) AS INTEGER) = 1
    
02.12.2015 / 11:20