Hi! I’m new to xojo, I’m getting stuck with this query on a mssql server db and a xojo webapp…
ps = db.Prepare(“SELECT DTA_STUDE.CODSTUDE, ANA_STUD.COGSTUDE, ANA_STUD.NOMSTUDE, DTA_STUDE.CODFSRED, DTA_STUDE.SALBUONI, DTA_STUDE.VALBUONI FROM DTA_STUDE INNER JOIN ANA_STUD ON DTA_STUDE.CODSTUDE = ANA_STUD.CODSTUDE WHERE DTA_STUDE.CODSCUOL = ? AND DTA_STUDE.CLASTUDE = ? AND DTA_STUDE.SEZSTUDE = ? AND DTA_STUDE.CODANNSC = ? AND ANA_STUD.TIPSTUDE= ‘S’ AND ANA_STUD.COGSTUDE LIKE ? ORDER BY ANA_STUD.COGSTUDE”)
ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.BindType(1, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.BindType(2, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.BindType(3, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.BindType(4, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.Bind(0, SpScuola.Text)
ps.Bind(1, SpClasse.Text)
ps.Bind(2, SpSezione.Text)
ps.Bind(3, Login_Page.SpAnnoSco.Text)
ps.Bind(4, RicercaCognome)
the problem is referring to a WebSearchField (is called RicercaCognome). If I put the entire value of the field (for example ‘ROSSI’) it works, but If I put only the beginning of the field value (for example ‘ROS’) no record is returned.
Maybe is wrong something in the query?
If you use LIKE in a PreparedStatement, you need to add % and _ to the String you Bind.
ROS% will find all that starts with ROS
%ROS will fin all that ends with ROS
%ROS% will find all that contains ROS
RO__I will find all that starts with RO followed by 2 chars and ends with I
and so on
To debug a query like this I would use some database access tool or a terminal session to verify that your query does in fact return the intended result (maybe you need ilike instead of like or something). Only once you know that you should tackle the task of turning that into a prepared query.