top_left top_right
bottom_left
Next Event: Unknown | Forum Rules | QGL Website | Event Registration
openFolder AusForums.com
iconwatfolderLineopenFolder LANs
iconwatfolderLineopenFolder QGL
iconwatfolderLineopenFolder QGL Forum
Author
Topic: sql divide question
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
system
--
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
stinky
Posts: 2435
Location: Brisbane, Queensland
What reason do you have for keeping minutes in a decimal form like that ?
big bear
Posts: 17
Location: Sunshine Coast, Queensland
the same reason your mum needs a cock in her

"cos she wants it"
Hogfather
Posts: 1627
Location: Cairns, Queensland
Use a DATETIME.
mooby
Posts: 3879
Location: UK
What reason do you have for keeping minutes in a decimal form like that ?


calculating payrolls. its a computed column based on start and finish times.
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.
natslovR
Posts: 1537
Location: Canberra, Australian Capital Territory
sql2008 has time, if you've got the time to wait for that.
Opec
Posts: 4990
Location: Brisbane, Queensland

calculating payrolls. its a computed column based on start and finish times.


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.


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.


Yes you can. SQL will implicitly convert the data to 1 decimal.
system
--
Not a new post since your last visit.
New Post Since your last visit
Back To Forum
Advertise with Us | Privacy Policy | Contact Us
© Copyright 2001-2026 AusGamers Pty Ltd. ACN 093 772 242.
Hosted by Mammoth Networks - Australian VPS Hosting
Web development by Mammoth Media.