1
I have the following code that lists certain trade agreements. You have the Yes or No option.
DECLARE @Opcao VARCHAR(7)
SET @Opcao = 'S'
SELECT * FROM
BLA BLA BLA
WHERE
((('{Opcao}' = 'S') AND NFDataEmis BETWEEN lme.LogMovEstqDataHora AND ppme.ParcPagMovEstqDataVenc) or ('{Opcao}' = 'N'))
AND ec.CategCodEstr like '{Categoria}' + '%'
AND crd.ClasseRecDespCodEstr like '{Acordo}' +'%'
AND me.MovEstqDataMovimento BETWEEN @Data_inicial AND @Data_final
What happens is that it brings me all the options that are listed the S and the N. I wanted to make a CASE to bring the options that are not in S and N. How could I do that?
SQL SERVER USAGE
I don’t quite understand it, but
Opcao NOT IN ('S', 'N')
or'{Opcao}' <> 'S'
doesn’t solve?– Barbetta
If the @Option variable is empty, it cannot execute (('{Option}' = ’S') AND Nfdataemis.... If it is S or N it executes. I tried with CASE but it didn’t work. As if it would be with IN?
– Felipe Michael da Fonseca
Oh yes, I get it, Option is a column of some table?
– Barbetta
No Option is a variable that will list the records by Date. If it is S it lists according to one category if N for another. But I want to list them all. So if it is by all it does not execute this line: ((('{Option}' = ’S') AND Nfdataemis BETWEEN lme.Logmovestqdatahora AND ppme.Parcpagmovestqdatavenc) or ('{Opcao}' = 'N'))
– Felipe Michael da Fonseca
I’m sorry. I don’t know if you’re slow. but it’s not clear to me yet, so it looks like the variables in
{}
comes from some code. but I found this response in the OS I might be able to help you– Barbetta
Really, the explanation is a bit confusing. But I think the final solution to our exact understanding may not be the issue at this point. Try to take a look at the answers and if they don’t fit, try to explain why they don’t work
– Alberto Cláudio Mandlate