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 |
|
dalibor
Starting Member
21 Posts |
Posted - 2009-04-16 : 06:04:52
|
| Hi all,I have SQL Server 2008 express (with SQL Management studio 10.0.1600.22)Try this:declare @pidi floatset @pidi = 1/2 -- 1/1440print @pidiResult: 0Why zero?Please help, i dont understant why zero.I am debugging and watching variable @pidi; always only zero, whole time ....Dalibor |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-04-16 : 06:20:47
|
Because 1 is an integer, not a float. If you do:declare @pidi floatset @pidi = convert(float,1)/2 -- 1/1440print @pidi You will get the correct answer as you are explicitly converting 1 to a float. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-16 : 06:26:46
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
dalibor
Starting Member
21 Posts |
Posted - 2009-04-16 : 06:29:02
|
| Yes, its work.Every time, when i need assign decimal value to variable, must use set set @variable = convert(float,1)/2 ?It is complicated, I think, but work it....Thanks |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-04-16 : 06:30:41
|
| Not if your variable is that type already. Read the link Madhivanan posted, I think it will explain the problem better. |
 |
|
|
dalibor
Starting Member
21 Posts |
Posted - 2009-04-16 : 07:52:04
|
| I read the link Madhivanan - very good link.Now understading.Thanks ! |
 |
|
|
|
|
|