Вопрос

I retrieve customer information by using

WHERE UPPER(CustomerName) LIKE UPPER('%ALAN%');

Now, I'd like to pass in a variable @CustomerName when I create a new stored procedure. So, I changed my query like this:

DECLARE @CustomerName Nvarchar(100);
SET @CustomerName = 'ALAN';

WHERE UPPER(CustomerName) LIKE UPPER(''%'' + @CustomerName + ''%'');

However, I am getting the following error:

The data types varchar and varchar are incompatible in the modulo operator.

I suspect that it is because of the single quote that I used wrongly. How can I update my query to get the result?

Это было полезно?

Решение

It should be just that below. You're concatenating string literals with a variable value, you don't need to do anything special.

DECLARE @CustomerName Nvarchar(100);
SET @CustomerName = 'ALAN';

WHERE UPPER(CustomerName) LIKE UPPER('%' + @CustomerName + '%');

Note, you didn't incluse SELECT part, so I didn't include it either.

Другие советы

there are extra quote is in your query, remove it =)

DECLARE @CustomerName Nvarchar(100);
SET @CustomerName = 'ALAN';

WHERE UPPER(CustomerName) LIKE UPPER('%' + @CustomerName + '%');

SAMPLE : http://sqlfiddle.com/#!6/c5424/5

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top