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)
 Formatting varchar-output

Author  Topic 

Makkaramestari
Starting Member

8 Posts

Posted - 2005-12-28 : 06:50:29
Hello!

I have two fields, Field1 and Field2, both int.
If Field1 contains 23 and Field2 contains 55, with CAST function
I manage to produce output looking like 23:55 (casting int to varchar). On the other hand, if Field1 contains 23 and Field2 contains 0, all I get is 23:0
How do I format it to look like 23:00?

Yours, Makkaramestari

sqlmember
Starting Member

7 Posts

Posted - 2005-12-28 : 07:14:52
try this

declare @a int, @b int
set @a = 23
set @b = 0
select right('00'+cast(@a as varchar(2)),2) + ':' + right('00'+cast(@b as varchar(2)),2)



-Khurram Iqbal
Go to Top of Page

Makkaramestari
Starting Member

8 Posts

Posted - 2005-12-28 : 07:25:36
Hi!

Thank you very much!

Makkaramestari
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-28 : 07:47:03
Where do you want to show these data?
If you use Front End Application use this type of formations there

Madhivanan

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

- Advertisement -