# Linear Regression Slope

Hello,

I am transferring an Access query to SQL Server.  One of the fields requires me to find the linear regression slope.  In Access, i used LinRegSlope() to find this.  Is there any way to do this in SQL Server?

Thanks!

-Navicerts
LVL 7
###### Who is Participating?

Commented:
try
x*x instead of x^2
or
pow(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float),2)
Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)^2
0

Commented:
Check if this one helps

http://support.microsoft.com/kb/307276
0

Author Commented:
That looks like information for MS Access, as i mentioned above, or am i missing something?  Is this SQL Server stuff?  If so, I am not having luck using this function.

Thanks
0

Author Commented:
I have three pertanant columns... ID, Weight, and Date.  I want the regression slope to be a function of weight gain over time.
0

Author Commented:
When i try to get the answer manually (no idea if im doing this correct) I get an error message....
Server: Msg 403, Level 16, State 1, Line 3
Invalid operator for data type. Operator equals boolean XOR, type equals float.

--SLOPE = ( COUNT(*)*SUM(x*y) -SUM(x)*SUM(y) ) / (COUNT(*)*SUM(x^2)-SUM(x)^2)
SELECT
(COUNT(*)*SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)*Weight) -SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float))*SUM(Weight) ) / (COUNT(*)*SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)^2)-SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float))^2)
FROM
WingbandFlock As wf
INNER JOIN
Weight As w
ON
wf.[Bird ID] = w.[Bird ID]
0

Author Commented:
I realized it was gain vs feed eaten as opposed to gain over time, but it was the ^ that had me all confused.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.