mercredi 25 novembre 2015

SQL Server - Getting the opposite of a where clause

I have a data set where I would like to filter out rows that meet a specific condition, however it's proving a lot more trickier than I thought it would do.

Essentially I want to do something along the lines of WHERE (column1 NOT LIKE 'Z%' and column2 != '2') with the view that the query will only return rows in which a specific row doesn't have the value like 'Z%' in column1 and doesn't have the value '2' in column2.

For example:

Full data set

column1 | column2
-----------------
ACAL    | 2
-----------------
ZVBBU3  | 2
-----------------
FSKE2   | X

Data set that I want

column1 | column2
-----------------
ACAL    | 2
-----------------
FSKE2   | X

However, it doesn't do that. So I thought there may be a programming approach like WHERE (!(column1 LIKE 'Z% and column2 = '2')) where ! will return the opposite of the criteria specified, but this throws a syntax error. Is there any way of doing what I want to achieve?

Aucun commentaire:

Enregistrer un commentaire