I have the following query:
from dbo.patient AS p
INNER JOIN dbo.study AS s
on s.patient_fk = p.pk
where s.study_datetime >= DATEADD(year, datediff(year, 1, getdate()), 0)
and s.study_datetime < DATEADD(year, datediff(year, -1, getdate()), 0)
order by s.study_datetime desc
this brings back the current year up to today's date.
result for example - here is one row: 2014-10-07 10:02:28.000
I want to edit this query to find all of 2013 only. From 1/1/2013 - 12-31-2013. Next I will need to do 2012 & so on, but I'm sure once I have it working for 2013, it will be easy to bring back 2012 & continue from there. How would I edit this to bring back all of those rows? Also, if someone could help explain how the 'DATEADD' & 'DATEDIFF' work together with in this example it would really help to shed some light on this logic for me.
EDIT: updated code above - typo