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
 General SQL Server Forums
 New to SQL Server Programming
 How to get all moths based on month

Author  Topic 

vandana
Starting Member

29 Posts

Posted - 2013-04-17 : 02:51:33
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-17 : 03:19:30
--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 - 2013-04-17 : 03:32:32
i wana do it without using t-sql
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-17 : 03:34:28
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
   

- Advertisement -