Insert apostrophes with variables

Asked

Viewed 101 times

0

I am performing a query through a value stored in a variable. This variable is declared DECLARE @it_codigo varchar(max) and gets value from a field ntext from another table, through a previous.

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

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

1 answer

0


to escape the ', use two apostrophes:

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

Browser other questions tagged

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