Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
How to get month number like Jan -01, Feb-02...
How to get month number like Jan -01, Feb-02 ... Instead of Jan-1, Feb-2
Rate Topic
Display Mode
Topic Options
Author
Message
gracebite
gracebite
Posted Tuesday, March 19, 2013 4:34 PM
Grasshopper
Group: General Forum Members
Last Login: Monday, May 13, 2013 5:59 PM
Points: 16,
Visits: 104
Hi,
Need help on get month number from Date field, I am getting month number as 1 for Jan, 2 for Feb
But I need 01 for Jan, 02 for Feb..like this
Can you please some one help me out
Thanks
Grace
Post #1432933
Lynn Pettis
Lynn Pettis
Posted Tuesday, March 19, 2013 4:37 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 3:09 PM
Points: 21,588,
Visits: 27,386
try this and see if it helps:
select right('0' + cast(month(getdate()) as varchar),2)
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1432934
Jeff Moden
Jeff Moden
Posted Wednesday, March 20, 2013 12:25 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 12:30 PM
Points: 32,893,
Visits: 26,770
Or maybe a little "silent truncation" (one of my favorite tools) is in order.
SELECT CONVERT(CHAR(2),GETDATE(),1)
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1433013
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.