Page 1 of 1

SQL TOP & Variable Issue

Posted: 29 Jan 2018, 09:15
by zoidberg
Hi guys,

I have a small issue with using a SQL script node variable to restrict the amount of selected datasets:
Here is my query:

SELECT AVG(R.ImpactAverage) AS ImpactAverageAll,
AVG(R.EconomicalAverage) AS EconomicalAverageAll,
AVG(R.CulturalAverage) AS CulturalAverageAll,
AVG(R.SocialAverage) AS SocialAverageAll,
AVG(R.GeopoliticalAverage) As GeopoliticalAverageAll,
COUNT(R.SessionId) As SessionsPlayed
FROM ( SELECT TOP @MaxHits
ImpactAverage,
EconomicalAverage,
CulturalAverage,
SocialAverage,
GeopoliticalAverage,
SessionId,
CreationTime
FROM Sessions
ORDER BY CreationTime DESC ) AS R


In variable @MaxHits I provide the number of dataset I wanna have for my average calculations. So if I use this variable I get an SQL error message inside of Ventuz that there is a syntax error near my @MaxHits variable. If i replace the variable with a number like 1000 the query is executed without any problems and I get my results.

Any ideas why this error occurs?

Thanks,
Anton