Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with math forumla within sql statement

Status
Not open for further replies.

WaveOut

Programmer
Sep 6, 2002
42
US
I need to calculate the following formula within an sql statement:

--Tsat = Ax + B/x + C(x^0.5) + D(ln(x)) + E(x^2) + F(x^3) + G

My first attempt is like so:

Local a real;
Local b real;
Local c real;
Local d real;
Local e real;
Local f real;
Local g real;
Local Tsat real;
Local P real;

a = -0.17724;
b = 3.83986;
c = 11.48345;
d = 31.1311;
e = 8.76E-05;
f = -2.79E-08;
g = 86.594;
P = 584.944;

Tsat = (a*P) + (b/P) + c*(P*exp(0.05)) + (d*(ln(P))) + e*(P*exp(2)) + f*(P*exp(3)) + g;

I do not get an error when I run this but the answer comes up wrong. If P = 584.944 then Tsat should equal 483.4151. This formula works correctly in excel so I know the formula is correct. Can anyone see where I went wrong in my formula?

Thanks,
Dave



 
This syntax is nothing like Microsoft SQL Server's. Are you using SQL Server or is it another type of database?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Are you using Microsoft SQl Server as that isn ot how you declare and use variables in t-SQL?

More than likely your problem is in using the real datatype. This is an approximate data type in SQl Server andshould never be used in amath calculation that requires an exact answer. Decimal datatypes are better for this type of calcuation.



Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top