I need to use a like based the DATO variable... first three char in NOMINATIVO
is this correct:
for example for DATO="ALL"
return
ALLEANZA
ALLEGRO
ALLEGORIA
....
DATO = Trim(Me.TCERCA.Text)
SQL = "SELECT * FROM DATI WHERE NOMINATIVO LIKE 'DATO*'"
i'm on Access and ADO, and vb6
use like with variable string
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: use like with variable string
No, you must place DATO outside the quotes and concatenate:
Code: Select all
SQL = "SELECT * FROM DATI WHERE NOMINATIVO LIKE '" & DATO & "*'"
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
Re: use like with variable string
OK.HansV wrote: ↑29 Jan 2022, 12:14No, you must place DATO outside the quotes and concatenate:
Code: Select all
SQL = "SELECT * FROM DATI WHERE NOMINATIVO LIKE '" & DATO & "*'"
but via code return 0!
in access ide return 107 records!!!
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: use like with variable string
Sorry, ADO uses % instead of *.
Code: Select all
SQL = "SELECT * FROM DATI WHERE NOMINATIVO LIKE '" & DATO & "%"
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
Re: use like with variable string
work!HansV wrote: ↑29 Jan 2022, 12:35Sorry, ADO uses % instead of *.
Code: Select all
SQL = "SELECT * FROM DATI WHERE NOMINATIVO LIKE '" & DATO & "%"
NOTE:
changed "%" with "%'"
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
Re: use like with variable string
Ops ...
Based the attached IMG how to add a new recorset for sort?
RS.sort(nominativo, collegio) in asc sort
Is correct?
Based the attached IMG how to add a new recorset for sort?
RS.sort(nominativo, collegio) in asc sort
Is correct?
Last edited by sal21 on 29 Jan 2022, 15:31, edited 1 time in total.
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: use like with variable string
You could use
or you can add the sort order to the SQL instead:
Code: Select all
RS.Sort = "nominativo ASC, collegio ASC"
Code: Select all
SQL = "SELECT * FROM DATI WHERE NOMINATIVO LIKE '" & DATO & "%' ORDER BY NOMINATIVO, COLLEGIO"
Best wishes,
Hans
Hans