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
 SQL Server Development (2000)
 hour

Author  Topic 

wided
Posting Yak Master

218 Posts

Posted - 2010-10-01 : 04:52:55

in database, i stock hour (int)

exemple 1290

with calculate or MS excel, if i do 1290/60 i have 21.5
with sql, i have 21 without .5

why?
i need help

thanks

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-01 : 05:08:38
it's an implicit conversion to integer arithmatic.

Try

SELECT 1290/60.0

And you'll get 21.5

If you need to do this in a set (for int columns) cast them to FLOAT or DECIMAL

Example

SELECT
[Col1] / CAST([col2] AS FLOAT)
FROM
<ExampleTable>


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-01 : 05:09:01
select 1290/60 -- gives 21
select 1290/60.0 -- gives 21.500000



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

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-01 : 05:09:27



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

- Advertisement -