List-based WHERE filter with SQL

Asked

Viewed 854 times

1

Good afternoon!

Please, I am making a Fiscias Notes 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 doesn’t get kilometric?

Note: Cfops do not follow a logical sequence to use a >= Or BETWEEN type filter

  • Explain a little better, you just want to use a Where list within sql itself or there is an application that will create the query?

  • Within the same SQL itself

  • And the CFOP values come from where? You will insert them in the same hand?

  • Yes, in the nail. There is no rule (yet) for the selection of Cfops, so go in the same race.

1 answer

2


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

Ex:

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

EDIT: To search in varchar field, just wrap the values with apostrophes.

Follows documentation.

  • Expensive, perfect. It worked even with the field in VARCHAR format. I didn’t know the IN clause. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.