Error with Like do sql

Asked

Viewed 92 times

5

How do I extract all fields starting with '1. ' from the BD? In my instruction I used the LIKE but had no return, but to remove the point already returns something, but returns fields I do not want, example: 10.1; What’s wrong with it.

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

  • which bank you’re using?

  • I’m using the access.

  • Apparently your code this coreto, no sql server it makes right, your C_numbering is of what type ?

  • Is of the text type.

  • Make sure you’re getting that figure right.

  • Solution: SELECT * FROM tbCellular WHERE Mid(C_numbering, 1, 2) = '1. '; Thank you all for your help.

  • I will remove my answer, to clear the area.

Show 2 more comments

1 answer

3


You can use the SubString:

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

Depending on the case you need to do a CAST on Substring passing it to Integer, anyway it is easy to do!

SELECT * FROM tbCelula WHERE CAST(SUBSTRING(C_Numeracao FROM 1 FOR 1) AS INTEGER) = 1
  • In my case I only had to exchange the substring for Mid, but the post helped. Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.