Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

How to get month number like Jan -01, Feb-02 ... Instead of Jan-1, Feb-2 Expand / Collapse
Posted Tuesday, March 19, 2013 4:34 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, August 29, 2014 11:07 AM
Points: 25, Visits: 152

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 this

Can you please some one help me out

Post #1432933
Posted Tuesday, March 19, 2013 4:37 PM



Group: General Forum Members
Last Login: Yesterday @ 6:24 AM
Points: 23,522, Visits: 37,765
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
Posted Wednesday, March 20, 2013 12:25 AM



Group: General Forum Members
Last Login: Yesterday @ 10:52 PM
Points: 42,083, Visits: 39,479
Or maybe a little "silent truncation" (one of my favorite tools) is in order.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

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."

Helpful Links:
How to post code problems
How to post performance problems
Post #1433013
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse