September 11, 2013 at 2:43 am
Team,
I have used format function sql server 2012 to get month number as "09"
select format(dateadd(m,-11,'2013-08-01'), 'MM')
Could you please help me to get same output in SQL server 2008.
Thanks in advance,
Keerthy
September 11, 2013 at 2:45 am
DATEPART() or MONTH(). Both return INT so you may need to CAST.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 11, 2013 at 2:50 am
Thanks for your quick reply, but we can use cast / convert only after applying datepart function.
It would be great, if you could able send test script.
September 11, 2013 at 2:54 am
JoyKing (9/11/2013)
Thanks for your quick reply, but we can use cast / convert only after applying datepart function.It would be great, if you could able send test script.
Yes, but if you were thinking of using CONVERT, then you would do it like this:
SELECT CONVERT(CHAR(2),GETDATE(),10)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 11, 2013 at 2:57 am
Better still, using your example:
SELECT CONVERT(CHAR(2),DATEADD(m,-11,'2013-08-01'),10)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply