0
I’m looking for a search and I’m not finding the right logic to filter the results I want.
I have a table with all the expiration registrations of certain equipment. My problem is related here:
- The Equipments (1, 22 and 23) are from the same group, so in case one of them shows up OK, do not want to list the other equipment of the group. If it appears all defeated, I want to list the 3 equipment as expired.
- Already the code equipment equal to 6 if you’re beat I want you to list, if you’re OK you don’t need to list.
So far I searched the values in the database and created a select to find the data I need, but I can’t filter the way I reported. Follows script:
SELECT
y.* FROM
(SELECT
e.numcad,
e.codepi,
Max(e.datent) AS Entrega,
Max(e.datent) + p.diaval AS Validade,
CASE
WHEN
Max(e.datent) + p.diaval <= Getdate()
THEN
'VENCIDO'
ELSE
'OK'
END
AS Situacao
FROM
r096die e, r096epi p
WHERE
e.numcad = 241
AND e.codepi IN (1, 22, 23, 6)
AND p.codepi = e.codepi
GROUP BY
e.codepi , e.numcad , p.diaval
) Y
GROUP BY y.numcad, y.codepi, y.entrega, y.validade, y.situacao
NOTE: I had to post as image because I could not add a table of results
I’d think of a fuction
– Motta
There are many unrelated criteria... I think you should do
subqueries
for each criterion and bring it all together at the end.– Ricardo Pontual