SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to fetch all records of given month
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

165 Posts

Posted - 04/07/2013 :  10:10:43  Show Profile  Reply with Quote

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


James K
Flowing Fount of Yak Knowledge

3849 Posts

Posted - 04/07/2013 :  20:45:17  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000