Avatar of EricLynnWright
EricLynnWrightFlag for United States of America

asked on 

Get Prior Month Number

Seeing if anyone has SQL on how to get the prior month (as a number) by using today's date.


So for this month, it would come back as 4.  In january, it would come back as 12.

etc....
Microsoft SQL ServerMicrosoft SQL Server 2008Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Andrew Crofts
ASKER CERTIFIED SOLUTION
Avatar of Andrew Crofts
Andrew Crofts
Flag of Ukraine image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Anuj
Anuj
Flag of India image

SELECT DATEPART(mm,DATEADD(mm,-1,getdate()))
Avatar of EricLynnWright

ASKER

Thank you for the posts.

anujnb - he beat you by just a minute.  But I certainly appreciate the help.
Avatar of Andrew Crofts
Andrew Crofts
Flag of Ukraine image

Thanks
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo