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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get all moths based on month
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vandana
Starting Member

29 Posts

Posted - 04/17/2013 :  02:51:33  Show Profile  Reply with Quote
Hi All,
i have a table which have product,amount,year,month are the fields.
now when in query when i give 2010(eg) year and month 10 i should get output like
2009's 12th month along with 2010's all months till 10
can anyone suggest me how to get it
thanks in advance

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 04/17/2013 :  03:19:30  Show Profile  Reply with Quote
--May be this?
DECLARE @Year INT = 2000, @Month INT = 10
SELECT *
FROM Products
WHERE (MonthCol <= @Month AND YearCol = @Year) or (YearCol = @YEAR-1)


--
Chandu
Go to Top of Page

vandana
Starting Member

29 Posts

Posted - 04/17/2013 :  03:32:32  Show Profile  Reply with Quote
i wana do it without using t-sql
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 04/17/2013 :  03:34:28  Show Profile  Reply with Quote
How you are passing inputs to the query?

SELECT *
FROM Products
WHERE (MonthCol <= 10 AND YearCol = 2010) or (YearCol = 2009)


--
Chandu
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