Results 1 to 5 of 5

Thread: SQL 2005 getting month as two digits [resolved]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Resolved SQL 2005 getting month as two digits [resolved]

    Hi All,

    For a quite convoluted reason I need to bulid a string which contains the month as two digits. I came up with the following sql statement
    Code:
    declare @month int
    set @month = (select cast(datepart(m,getdate()) as integer))
    declare @lmonth varchar(2)
    set @lmonth =  CASE 
             WHEN  @month <10   THEN '0' + cast(@month as varchar)
             ELSE cast(@month as varchar)
          END
    select @lmonth
    But seems to me there must be a much much sleaker way to achive the same thing, any help would be appreciated.
    Last edited by Oliver1; Jul 7th, 2009 at 07:53 AM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width