Query of matches does not show record

2

I have a SQL query which looks for a table according to four parameters or if there are no parameters returns all the records in the table, the problem is that when searching for a title no results return and it is assumed that if have a match with any record in the sql table, I think that I have mistaken my Query especially in the LIKE

    CREATE PROCEDURE [dbo].[ProcListarpProyectosEfectivo]
    (   
    @DescripcionProyecto VARCHAR(100) =NULL ,
    @TituloProyecto VARCHAR(50) =NULL ,
    @FechaInicio DATE =NULL ,
    @FechaFin DATE =NULL 
    )
AS
BEGIN
    SET NOCOUNT OFF;
    BEGIN TRY
    SELECT 
        ID_Proyecto,
        DescripcionProyecto,
        TituloProyecto,
        FechaInicio,
        FechaFin
 FROM PROYECTOS WHERE 
    (DescripcionProyecto like '%@DescripcionProyecto%' OR @DescripcionProyecto IS NULL) AND 
    (TituloProyecto like '%@TituloProyecto%' OR @TituloProyecto IS NULL) AND 
    (FechaInicio=@FechaInicio OR @FechaInicio IS NULL) AND 
    (FechaFin=@FechaFin OR @FechaFin IS NULL) AND       
    (Eliminado <> 1)
    END TRY
    BEGIN CATCH
        EXEC ProcMensajeError 
    END CATCH
END
    
asked by Ivxn 03.01.2018 в 23:35
source

1 answer

4

When you do:

like '%@DescripcionProyecto%'

... is not using the value within the variable @DescripcionProyecto . Rather, you are literally looking for a "@DescripcionProyecto" chain.

To use the variable correctly, you must do it this way:

like '%' + @DescripcionProyecto + '%'
    
answered by 03.01.2018 / 23:40
source