Insert apostrophes with variables

0

I'm doing a query through a value stored in a variable. This variable is declared DECLARE @it_codigo varchar(max) and gets value of a ntext field from another table, through a procedure.

SELECT * FROM anaProdutos WHERE cod_produto LIKE  '' + @it_codigo + ''

I also tried to use the QUOTENAMES function and still does not insert the apostrophes.

    
asked by anonymous 19.04.2016 / 14:24

1 answer

0

To escape ', use two apostrophes:

SELECT * FROM anaProdutos WHERE cod_produto LIKE '''' + @it_codigo + ''''
    
19.04.2016 / 14:35