Anyone know if it's possible to code this as part of a WHERE clause of a SELECT?
Text:
WHERE
DEGEST must exist where COM is between 01/08/15 and 31/07/16
and AIM is in (020, 021 or 031) unless CTRY exists
I can code it ok until the last part i.e. coding the 'unless CTRY exists
Select
case
when YourColumnField = 'CTRY' then 'CTRY'
when AIM in (020,021,031) then 'What ever you want to call it'
End as Name
,*
from yourtable
Where
YourColumnField = 'DEGEST'
and COM between '20150801' and '20160731'
and (YourColumnField = 'CTRY' or AIM in (020,021,031))
Select 'DEGEST' as Flag,* from yourtable
Where YourColumnField = 'DEGEST'
and COM between '20150801' and '20160731'
and AIM in (020,021,031)
Union all
select 'CTRY' as Flag,* from yourtable
Where YourColumnField = 'CTRY'
WHERE
DEGEST in ( select degest from yourtabledegest
where yourtabledegest.COM between 01/08/15 and 31/07/16)
and AIM is in (020, 021 or 031)
and CTRY not in (select CTRY FROM yourtablectry.CTRY
WHERE XXXXXXXX)
I can code it ok until the last part i.e. coding the 'unless CTRY exists