1
Guys, I got the following Union:
select cgc, item, matricula, cota, dataInicio, dataFim
from [dbo].[cotas] as t1
where dataFim is null
union
select cgc, item, matricula, cota, dataInicio, dataFim
from [dbo].[cotas] as t2
where dataInicio >='01/05/2019' and dataFim<='31/05/2019'
só que eu preciso fazer um resultado final... em que t1.cgc seja diferente de t2.cgc
It turns out that when the Fim date is null, it means that the quota is active. And when it is filled in, the quota is inactive. An employee may have inactive quotas in the CGC that currently works, but there is no way to have active quotas in a CGC that has already worked and no longer works. Only that the employee (enrollment) may have worked in more than one CGC in the same month. I need to take all quotas that are active. And, just take the inactive ones that are from a cgc that he worked on previously.
Does anyone know how to do this with Union? Or should I do it another way? Thank you.
I couldn’t understand your explanation, what is the outcome you expect to return? You want all active CGC accounts that would be the accounts where Im is null and inactive accounts that have the dataFim is not null and t2,cgc not in (SELECT t1.cgc from [dbo]. [quotas] WHERE Where dataFim is null).
– Marcus Italo