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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

asifbhura
Posting Yak Master

India
165 Posts

Posted - 04/07/2013 :  10:10:43  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3873 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  
 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.04 seconds. Powered By: Snitz Forums 2000