PQTIII
IS-IT--Management
- Sep 21, 2004
- 110
What is the correct where statement to show my all the records in the current month or month to date?
Thanks pt
Thanks pt
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
-- first
select *
from myTable
where year(datecolumn) = year(getdate()) and month(datecolumn) = month(getdate())
-- second
select *
from myTable
where datediff(mm, datecolumn, getdate()) = 0
-- third
declare @lodate datetime; set @lodate = dateadd(mm, datediff(mm, 0, getdate()), 0)
declare @hidate datetime; set @hidate = dateadd(mm, 1, @lodate)
select *
from myTable
where datecolumn >= @lodate and datecolumn < @hidate