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 2000 Forums
 Transact-SQL (2000)
 How to return 5 as 05?

Author  Topic 

mark1504
Posting Yak Master

103 Posts

Posted - 2005-05-26 : 11:27:08
Let's say i have fields in a table: hours (int), minutes (int).

What's the best method of returning the time in a string format of, for example: 09:00. In other words, how do I pad a single number with a 0 when necessary?

Thanks
Mark

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2005-05-26 : 11:30:58
RIGHT('00' + CAST(Hours AS VARCHAR), 2) should do it.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

mark1504
Posting Yak Master

103 Posts

Posted - 2005-05-26 : 11:39:09
Thanks Graz

Rapid response as usual!

(I'd been looking for something in CAST or CONVERT and didn't find it.)

Regards
Mark
Go to Top of Page
   

- Advertisement -