Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Linear Regression Forecast

By msdevpro,

PRINT dbo.ufn_LinearForecast(0, '552,6:313,5:1213,4:1204,3:721,2:428,1')

SELECT
dbo.ufn_LinearForecast(0,
CAST(JanSales as varchar) + ',' + '1:' +
CAST(FebSales as varchar) + ',' + '2:' +
CAST(MarSales as varchar) + ',' + '3:' +
CAST(AprSales as varchar) + ',' + '4:' +
CAST(MaySales as varchar) + ',' + '5:' +
CAST(JunSales as varchar) + ',' + '6:') AS Forecast
FROM dbo.SalesSummary
WHERE InvoiceDate >= '1/1/2009' AND InvoiceDate < '7/1/2009'

Total article views: 2186 | Views in the last 30 days: 11
 
Related Articles
FORUM

varchar issue

varchar issue

FORUM

Tricky ...VARCHAR

VARCHAR logics

FORUM

Difference between varchar(max) and varchar(8000)

Difference between varchar(max) and varchar(8000)

FORUM

converting varchar to numeric

converting varchar to numeric

FORUM

VARCHAR(x) VS VARCHAR(MAX)

any downside to VARCHAR(MAX)?

Tags
forecast    
linear    
math    
regression    
trend    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones