tags:

views:

83

answers:

8

Hi, I do not understand why 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

A: 

% is a wildcard expression, which is probably the reason why; I think you may, if you want a literal %, wrap it in square braces [%], but I actually forget if that is the answer, and apologize if it isn't.

If you want to use it as where the column doesn't have the text test in it, then you do:

where column1 not like '%Test%'

Brian
You need to say `Column1 NOT LIKE '%TEST%'`. ...and this was supposed to be an answer, not a comment >_>
Matti Virkkunen
Sorry, it was unclear. I really mean % to be used here as wildcard expression. Therefore IMHO it should ignore any row that contain TEST
Petr
+8  A: 

Use LIKE operator with Wildcards %:

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

try

SELECT [column1], [column2]
FROM table where Column1 NOT LIKE '%TEST%'
ORDER BY 1
KM
A: 

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

Matti Virkkunen
A: 

Did you mean using like?

where Column1 not like '%TEST%'

Andrew Bezzub
A: 

use Column1 NOT LIKE '%TEST%'

kevchadders
+2  A: 

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

SELECT [column1], [column2]
FROM table where Column1 NOT LIKE ('%TEST%')
ORDER BY 1
Oded
+4  A: 

If you want to use wildcards you have to use the LIKE operator:

SELECT [column1], [column2]
FROM table where Column1 NOT LIKE '%TEST%'
ORDER BY 1
despart
My god :D Sure... Sorry for stupid question, I am tired of it today.
Petr