Calculate SLOPE - Excel functionality

  • hi friends,

    I am just wondering if some one knows the way to find out SLOPE using T-SQL script. It is function in Excel but dont know if we can do something similar using T-SQL. The link below explains how it works for Excel.

    http://support.microsoft.com/kb/828142

    I tried few bits without luck.

    Can any one help?

    Thanks.

  • I got the solutions....

    -- Create a test table

    CREATE TABLE [TESTSTATS]( intKey INT, x FLOAT, y FLOAT)

    -- Populate the test table with random data

    DECLARE @intCount INT

    SET @intCount = 1

    WHILE @intCount < 11

    BEGIN

    INSERT INTO [TESTSTATS]

    SELECT @intCount, @intCount, 5.12 * @intCount + 7 * rand()

    SET @intCount = @intCount + 1

    END

    --– Get the Slope

    SELECT (count(x)*sum(x*y) - sum(x)* sum(y))/(count(x)*sum(x*x) - sum(x)* sum(x))

    FROM [TESTSTATS]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply