| Author |
Topic |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-11-18 : 11:21:51
|
| Hi GuysHow would u get the answer to a higher number divided by lower number to give u something apart from 0.For exampleSELECT 5/7In theory this should equal 0.714, but when I do it in SQL it gives me 0.Any ideas?Thanks |
|
|
R
Constraint Violating Yak Guru
328 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-18 : 11:33:33
|
| SELECT 5.0/7 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-18 : 11:34:16
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-11-18 : 11:35:43
|
| try,SELECT 5.0/7orSELECT 5/7.0orSELECT 5.0/7.0Dividing an integer by an integer shall give you int values. Make one or both float, and it should give you float values. |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-11-18 : 11:40:03
|
| Thanks guys.I was using SELECT 5/7 as an example, the actual query is:SELECT SUM(#Current.SalesUNits_WithoutMag)/SUM(#Previous.Prev_SalesUnits_WIthOutMag) FROM #Currentjoin #Previous on #Current.subCategoryId = #Previous.subCategoryIDGiving a result of 0 when it should be something else. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-18 : 11:41:55
|
quote: Originally posted by rcr69er Thanks guys.I was using SELECT 5/7 as an example, the actual query is:SELECT SUM(#Current.SalesUNits_WithoutMag)*1.0/SUM(#Previous.Prev_SalesUnits_WIthOutMag) FROM #Currentjoin #Previous on #Current.subCategoryId = #Previous.subCategoryIDGiving a result of 0 when it should be something else.
modify as above and see. reason same as before |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-11-18 : 11:42:26
|
quote: Originally posted by rcr69er Thanks guys.I was using SELECT 5/7 as an example, the actual query is:SELECT SUM(#Current.SalesUNits_WithoutMag)/SUM(#Previous.Prev_SalesUnits_WIthOutMag) FROM #Currentjoin #Previous on #Current.subCategoryId = #Previous.subCategoryIDGiving a result of 0 when it should be something else.
use CONVERT function to convert to float. |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-11-18 : 11:50:40
|
| Thanks Guys!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-18 : 12:00:54
|
quote: Originally posted by sakets_2000
quote: Originally posted by rcr69er Thanks guys.I was using SELECT 5/7 as an example, the actual query is:SELECT SUM(#Current.SalesUNits_WithoutMag)/SUM(#Previous.Prev_SalesUnits_WIthOutMag) FROM #Currentjoin #Previous on #Current.subCategoryId = #Previous.subCategoryIDGiving a result of 0 when it should be something else.
use CONVERT function to convert to float.
no need of explicit conversion. see my suggestion |
 |
|
|
|