|
![]() |
|
| Author |
|
|||||||
|
mooby
Posts: 3876
Location: UK
|
Hi there.
Im storing "minutes" as a decimal(9,2) in a ms sql db. However, I need to see the data as "decimal" hours. EG: 75mins = 1.25 If i do a Select minutes / 60 I just get a 1.00 |
|||||||
| #0 09:52pm 12/03/08 |
|
|||||||
|
system
|
--
|
|||||||
| #0 |
|
|||||||
|
mooby
Posts: 3877
Location: UK
|
oops, fixed (dam cold!)
declare @h as decimal(9,2) set @h = 71.00 set @h = @h / 60 print @h |
|||||||
| #1 09:54pm 12/03/08 |
|
|||||||
|
stinky
Posts: 2435
Location: Brisbane, Queensland
|
What reason do you have for keeping minutes in a decimal form like that ?
|
|||||||
| #2 10:17pm 12/03/08 |
|
|||||||
|
big bear
Posts: 17
Location: Sunshine Coast, Queensland
|
the same reason your mum needs a cock in her
"cos she wants it" |
|||||||
| #3 10:30pm 12/03/08 |
|
|||||||
|
Hogfather
Posts: 1627
Location: Cairns, Queensland
|
Use a DATETIME.
|
|||||||
| #4 10:36pm 12/03/08 |
|
|||||||
|
mooby
Posts: 3879
Location: UK
|
What reason do you have for keeping minutes in a decimal form like that ? |
|||||||
| #5 01:47am 13/03/08 |
|
|||||||
|
Mantis [OSWEC]
Posts: 188
Location: Brisbane, Queensland
|
Can't you just do "/ 60.0" instead of "/ 60". Can't remember for sure but thought that worked because both values were decimals so result was too.
|
|||||||
| #6 09:47am 13/03/08 |
|
|||||||
|
natslovR
Posts: 1537
Location: Canberra, Australian Capital Territory
|
sql2008 has time, if you've got the time to wait for that.
|
|||||||
| #7 09:51am 13/03/08 |
|
|||||||
|
Opec
Posts: 4990
Location: Brisbane, Queensland
|
Why would you need a computed column for something that simple, if you're already stored start and finish time (presumably in date/time data type) ? You can just calculate the hours on the fly without having to use either trigger or calculation in your app? I mean it's a simple matter of just use a DATEDIFF(n, start, end)/60.00, that'll give you exactly what you wanted. ? Unless you've created a calculated column for some special reason like you index it for something? I mean if you're doing some Data Warehousing that needs to do a range look up to build your fact table then it'd make more sense to store such simple values.
Yes you can. SQL will implicitly convert the data to 1 decimal. |
|||||||
| #8 11:52am 13/03/08 |
|
|||||||
|
system
|
--
|
|||||||
| #8 |
|
|||||||
|
| ||||||||