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
 General SQL Server Forums
 New to SQL Server Programming
 calculating in a statement

Author  Topic 

m4tt
Starting Member

13 Posts

Posted - 2008-03-03 : 11:45:46
Hi,
Im building a DB for a uni project and im having a little trouble creating a column that makes a calculation using 2 of the other columns.

I need to do this;
Select Reps, Weight, ((Reps / 30) + 1) * Weight AS [1RM]
From ......

But, SQL server 2005 doesnt seem to like my syntax and gives a wrong result.
Can anyone help?

Thanks,
M4tt

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-03 : 12:06:51
use 30.0 instead of 30

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

m4tt
Starting Member

13 Posts

Posted - 2008-03-04 : 04:42:12
Thanks Madhivanan!!!! Works perfectly now
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-04 : 05:02:18
Syntax is fine.
You just happened to use integer division.
By chaing 30 to 30.0 yoy now use "normal" arithmetic.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-04 : 07:38:50
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -