Hi
I want query which returns the last month from the current date.
for ex: if i enter today date then it should return the 12.
if i enter the date '2010-02-31' then it should return 1
thanks
Want query in sql server
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Gaurish Kumar108 reputationPosted Jan 31, 2010, 6:41 PM EST
try this
SELECT DATEPART(MONTH,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(GETDATE())),GETDATE()),101))
this query returns what you want.
Imran3 reputationPosted Jan 31, 2010, 6:47 PM EST
it's solve my problem.