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
 General SQL Server Forums
 New to SQL Server Programming
 not getting right answer

Author  Topic 

pnasz
Posting Yak Master

101 Posts

Posted - 2010-12-05 : 06:18:33
declare @time int
set @time = 609

select cast((@time / 60) as varchar(2)) + ':' + cast((@time % 60) as varchar(2))


should return

10.09

where i am wrong

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-05 : 06:57:31
select cast((@time / 60) as varchar(2)) + ':' + right('00'+cast((@time % 60) as varchar(2)),2)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pnasz
Posting Yak Master

101 Posts

Posted - 2010-12-05 : 07:57:16
is there anyway to convert it to integer as answer we are getting in varchar
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-05 : 09:05:39
10.09 isn't integer but I think you mean this:

declare @time int
set @time = 609

select (@time / 60) + (@time % 60/100.0)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-12-05 : 10:44:49
This might be better:
SELECT RIGHT(CONVERT(char(8), DATEADD(s, @time, 0), 8),5)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-05 : 10:55:12
No he wanted 10.09 instead of 10:09


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2010-12-05 : 11:05:02
Just be careful because 10:09 <> 10.09 if you are going to be aggregating time. 9/60 is a lot different than 9/100....




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page
   

- Advertisement -