Procedure does not return the select data

Asked

Viewed 388 times

1

I created a simple process, it takes a parameter and should return the data according to this parameter:

CREATE PROCEDURE [dbo].[testeLike]
    -- Add the parameters for the stored procedure here
    @teste varchar(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    select * from teste
        where valor like '@teste%'
END

executing the proc:

inserir a descrição da imagem aqui

did not return any data:

inserir a descrição da imagem aqui

But if I take the select code and test it, the data is returned:

select * from teste
        where valor like 'tes%'

inserir a descrição da imagem aqui

I can’t understand what the problem is. In the parameter I tried to pass with simple quotes, but gave anyway.

1 answer

1


I discovered the problem. It was time to pass the parameter in select, the correct is so:

select * from Produto
        where nome like @teste+'%'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.