List based WHERE filter with SQL

1

Good afternoon!

Please, I am doing a Notes Filters filter based on a series of CFOPs with SQL. It works like this:

SELECT * FROM NotasFiscais 
WHERE CFOP = 5101 OR CFOP = 6101 OR CFOP = 5922 OR CFOP = 6922 OR CFOP = 5933 CFOP = 6933 OR ....... CFOP = N

How can I create a list of CFOPs to be passed in the WHERE clause so my code does not stay in the kilometer?

Note: CFOPs do not follow a logical sequence to use a filter of type

asked by anonymous 04.02.2015 / 13:14

1 answer

2

A workable solution is the use of the IN clause, where it will bring all the results corresponding to the values passed by parameter.

Ex:

SELECT * FROM NotasFiscais
WHERE CFOP IN('5101', '6101', ...)

EDIT: To search in the varchar field, simply enclose the values with apostrophes.

Follow documentation .

    
04.02.2015 / 13:23