Select cusip
from mhfspric
where
PriceDate = case (Month(max(PriceDate)))
when 1
Then '12-31-2014'
when 2
Then '12-31-2014'
when 3
then '12-31-2014'
ELSE Null
END
group by cusip
I need to have a case statement to get the quarter ending dates for different months of pricedate
.
select distinct c1 as Cusip,
c2 as PriceDate,
c3 as PriceToDate,
c4 as PriceSource
from
(select c8 as c1,
c11 as c2,
c10 as c3,
c9 as c4,
c7 as c5
from
(select T1."Cusip" as c6,
MAX(T1."PriceSource") as c7
from "mhfspric" T1
where T1.PriceDate = (select case (Month(max(T2.PriceDate)))
when 1
Then '12-31-2015'
when 2
Then '12-31-2015'
when 3
then '12-31-2015'
when 4
then '03-31-2015'
when 5
then '03-31-2015'
when 6
then '03-31-2015'
when 7
then '06-30-2015'
when 8
then '06-30-2015'
when 9
then '06-30-2015'
when 10
then '09-30-2015'
when 11
then '09-30-2015'
when 12
then '09-30-2015'
ELSE Null
END
from mhfspric T2)and T1."PriceSource" <> 91
group by T1."Cusip"
) D3,
(select T1."Cusip" as c8,
T1."PriceSource" as c9,
T1."PriceToDate" as c10,
T1."PriceDate" as c11
from "mhfspric" T1
where T1.PriceDate = (select case (Month(max(T2.PriceDate)))
when 1
Then '12-31-2014'
when 2
Then '12-31-2014'
when 3
then '12-31-2014'
when 4
then '03-31-2015'
when 5
then '03-31-2015'
when 6
then '03-31-2015'
when 7
then '06-30-2015'
when 8
then '06-30-2015'
when 9
then '06-30-2015'
when 10
then '09-30-2015'
when 11
then '09-30-2015'
when 12
then '09-30-2015'
ELSE Null
END
from mhfspric T2)and T1."PriceSource" <> 91
) D2
where ((c8 = c6) or ((c8 IS NULL) and (c6 IS NULL)))
) D1
where (c4 = c5)
)
This is the entire sql. I need to get the max price date and if it falls in the first 3 months of a year then if has to the previous quarter ending. For ex if max pricedate is 04-13-2015 then the pricedate should be 03-31-2015. How do I make this code generic instead of hard coding for each year.??
Please help. Thank you