Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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: 2440 | Views in the last 30 days: 22
 
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