Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current year's records from a view in SQL Server

Tags:

sql-server

I have a view called vwMemberPolicyInfo and I need to display all records entered in current year.

My query is :

select  
    EffectiveDate AS [Month], 
    count(MemberID) AS Agents, 
    sum(ActualPremium) AS Premium
from 
    vwMemberPolicyInfo 
Where 
    EffectiveDate > DATEADD(year, -1, GETDATE())
GROUP BY 
    EffectiveDate 

but it is not working fine it show result:

2010-11-01 00:00:00.000 74  40644.00
2010-07-01 00:00:00.000 86  50418.00

2011-03-08 00:00:00.000 1   744.00
2011-04-08 00:00:00.000 1   0.00
2010-11-02 00:00:00.000 5   2676.00

2011-04-14 00:00:00.000 1   1185.00
2011-02-28 00:00:00.000 7   2988.00

2011-02-23 00:00:00.000 8   8518.00
2011-04-10 00:00:00.000 1   1332.00
2011-04-07 00:00:00.000 3   2544.00

I need only the current year entries to display ..thanks in advance

like image 871
Noor Rahman Avatar asked Dec 08 '25 10:12

Noor Rahman


1 Answers

Try where YEAR(EffectiveDate) = YEAR(GETDATE())

Hope it helps.

like image 108
icesar Avatar answered Dec 10 '25 02:12

icesar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!