none
How to create a select statement in a Table-adapter using Where Like RRS feed

  • Question

  • Hello

    I would like to create a Select statement unsing the where like but i am just no getting the syntax right this is what i have

    SELECT        Codigo, Descripcion, IdCategoria, FechaVencimiento, IdMarca, IdTipo, IdUsuario, FechaEditado
    FROM            dbo.TareaArticulos 
    where          Codigo   Like '%  + @ Codigo  + %'

    Basically what i want is that when i sand the parameter codigo it does not have to be a exact match it will still bring it up.

    so if i send in Codigo Xm it will bring up XM100.

    Any help in this will be appreciated

    Thursday, August 22, 2019 6:23 PM

Answers

  • Check this:

       where Codigo LIKE '%' + @Codigo + '%'

    and make sure that @Codigo does not contain special characters (such as ‘%’, ‘[‘, ‘_’) that affect the LIKE operation.

    Or use

       where Codigo like @Codigo

    if you prepare the @Codigo value separately.

    Also consider

       where CHARINDEX(@Codigo, Codigo ) > 0

    • Marked as answer by Zarelious Thursday, August 22, 2019 8:44 PM
    Thursday, August 22, 2019 7:00 PM

All replies

  • Check this:

       where Codigo LIKE '%' + @Codigo + '%'

    and make sure that @Codigo does not contain special characters (such as ‘%’, ‘[‘, ‘_’) that affect the LIKE operation.

    Or use

       where Codigo like @Codigo

    if you prepare the @Codigo value separately.

    Also consider

       where CHARINDEX(@Codigo, Codigo ) > 0

    • Marked as answer by Zarelious Thursday, August 22, 2019 8:44 PM
    Thursday, August 22, 2019 7:00 PM
  • so if i send in Codigo Xm it will bring up XM100.

    Any help in this will be appreciated

    WHERE Codigo LIKE '%xm%'

    If you use a variable

    DECLARE @keyword varchar(20);

    SET @keyword = 'xm';

    WHERE Codigo LIKE '%' + @keyword + '%';


    A Fan of SSIS, SSRS and SSAS


    Thursday, August 22, 2019 7:10 PM
    Answerer
  • Check this:

       where Codigo LIKE '%' + @Codigo + '%'

    and make sure that @Codigo does not contain special characters (such as ‘%’, ‘[‘, ‘_’) that affect the LIKE operation.

    Or use

       where Codigo like @Codigo

    if you prepare the @Codigo value separately.

    Also consider

       where CHARINDEX(@Codigo, Codigo ) > 0

     Thanks it works now funny thing is i tried the first two and it will not work.

    The third way works like  a champ. 

    where CHARINDEX(@Codigo, Codigo ) > 0

    No idea why, I will play with them some more so figure out why.

    Thanks again

        
    Thursday, August 22, 2019 8:44 PM