Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to fetch all records of given month

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2013-04-07 : 10:10:43
Hello,

I have one column like invoice_date in my table

i will pass month and year

i want all records of given month and year

Regards



James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-07 : 20:45:17
Query like this:
declare @year int = 2008;
declare @month int =3;
declare @FirstDayOfTheMonth datetime = dateadd(mm,@month-1,dateadd(yy,@year-1900,0));
select * from YourTable
where invoice_date >= @FirstDayOfTheMonth
and invoice_date < dateadd(mm,1,@FirstDayOfTheMonth);
Go to Top of Page
   

- Advertisement -