Greetings to all. I have the following problem. I have a stored procedure in SQL Server that retrieves data with the like operator, but it doesn't work for me.
create procedure recupera_art
@cadena char(40)
select * from articulo where clave like '%'+ @cadena +'%'
change the procedure like this:
create procedure recupera_art
@cadena char(40)
select * from articulo where clave like @cadena
and from my application (vb.net) I pass the parameter like this:
cmd.Parameters.AddWithValue("@cadena", "%" + dts.gclave_art + "%")
but it works halfway for me, that is, I have the following keys (AX101080,...,AX101095), when I want to do the query it does nothing for me when I put A, AX, AX1 or AX10, I have to put AX101 so that it starts to filter all the data in the table.
What I want is that by putting AX, A, AX1 or AX10 I can filter the data, I think that is possible.
I appreciate your cooperation in solving the problem.
Thank you all for your collaboration, I leave the solution in case someone happens to you.
In the app.
The explanation of the problem is that a
char(40)
physically uses the full space, this can be verified with this example:The exit:
By doing
like '%'+ @cadena +'%'
when@cadena
it is aCHAR
we are actually doing:Causing that we cannot find the desired information.
If your procedure works correctly in SQL you could try executing it as if it were t-sql
In the same way, if your procedure already has '%', you do not need to add it to your code in vb, I would also recommend that you change that char(40) to varchar(max)