SQL: column <> '% TEST%' does not work, why?

I do not understand why the following code does not work?

 SELECT [column1], [column2] FROM table where Column1 <> ('%TEST%') ORDER BY 1 

I want to have all rows where Column1 does not contain TEST

thanks

+4
source share
7 answers

Use LIKE with Wildcards %:

 SELECT [column1], [column2] FROM table WHERE Column1 NOT LIKE ('%TEST%') ORDER BY 1 
+8
source

If you want to use wildcards, you must use LIKE :

 SELECT [column1], [column2] FROM table where Column1 NOT LIKE '%TEST%' ORDER BY 1 
+6
source

Wildcards ( % ) in SQL should be used in conjunction with the LIKE statement:

 SELECT [column1], [column2] FROM table where Column1 NOT LIKE ('%TEST%') ORDER BY 1 
+2
source

to try

 SELECT [column1], [column2] FROM table where Column1 NOT LIKE '%TEST%' ORDER BY 1 
+1
source

% is a wildcard expression, which is probably the cause; I think you can, if you want to get the% literal, wrap it in square brackets [%], but I will really forget if this is the answer, and sorry if it is not.

If you want to use it so that there is no text test in the column, follow these steps:

where column1 is not like "% Test%"

0
source

You need to specify Column1 NOT LIKE '%TEST%' .

0
source

Did you mean using like?

where Column1 not like '%TEST%'

0
source

Source: https://habr.com/ru/post/1307031/


All Articles