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.
| Author |
Topic |
|
g_r_a_robinson
Starting Member
45 Posts |
Posted - 2004-01-28 : 21:04:38
|
| HiI'm inserting a decimal value into my db but it keeps round it of to a single figure. Its the result of time between two times. ie between 1:00 and 2:30 equals 2.5. But it ends up as 2 in the db even though the db field is also decimal. I know by looking at the watch in the bugger that its actually a decimal value just prior to insertion which only leads me to suspect that sql server is doing the rounding of, maybe this is the default behaviour but i need it to store the values as decimal. |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2004-01-28 : 23:26:27
|
| post some code so we can help you out.-ec |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2004-01-29 : 06:15:49
|
| Just a thought but what is the scale of your decimal db fieldBOL: Scale - the number of digits that can be placed to the right of the decimal pointIf it is zero then it will only accept the value to the left of the decimal point without rounding - 2.9 would be stored as 2 not 3Edit: The above is not exactly true. Just tried it and SQL server will round the value in TSQL but if you insert a value via EM then it takes the left hand value |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-01-29 : 12:48:31
|
Huh?DECLARE @x decimal(3,2), @y decimal(3,2)SELECT @x = 1.00, @y = 2.30SELECT @x, @y, @y-@xquote: Originally posted by g_r_a_robinson HiI'm inserting a decimal value into my db but it keeps round it of to a single figure. Its the result of time between two times. ie between 1:00 and 2:30 equals 2.5. But it ends up as 2 in the db even though the db field is also decimal. I know by looking at the watch in the bugger that its actually a decimal value just prior to insertion which only leads me to suspect that sql server is doing the rounding of, maybe this is the default behaviour but i need it to store the values as decimal.
Brett8-) |
 |
|
|
nricardo
Starting Member
17 Posts |
Posted - 2004-01-29 : 19:03:37
|
| You did not post code, so I'll assume you are using datediff. The results are always an integer and always the number of boudaries crossed. From 1:00 pm to 2:30 pm is only one hour. You cross the boundary from 1 to 2. To do what you want try using minutes and divide the result be 60. e.g. x = datediff(minute, start_time, end_time)/60. |
 |
|
|
g_r_a_robinson
Starting Member
45 Posts |
Posted - 2004-02-02 : 20:18:33
|
| Sorry guys, It was actually down to the fact that I didn't change the scale in my db and so it was truncating my values. The guy in the second post got me looking at this. I only just figured it out.Thanks for all your help |
 |
|
|
|
|
|
|
|