Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Format string (Transact-SQL)

Author  Topic 

rbfigueira
Starting Member

4 Posts

Posted - 2009-08-24 : 11:21:39
Hi,

Can anyone tell me the best way to format one string ?

Example:
select CONVERT(char (2),month(getdate()))

Result:
----
8

When the result is only one caracter I must to add the zero "0" on left. In this case I must have 08 as result.

Result:
----
08

Thanks

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-24 : 11:33:08
Try this

SELECT Replace(Str(month(getdate()), 2), ' ', '0')

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-25 : 03:06:29
Where do you want to show converted months?

If you use front end application, use format function there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -