How can a query like this be made?
SELECT
PersonId,
Name,
(
DECLARE @p INT=(SELECT (Not1 + Not2 + Not3)/3 FROM Tablo_Not WHERE NotId=PersonId);
DECLARE @s INT;
IF @p>84
SET @s=5;
ELSE IF @p>69
SET @s=4;
ELSE IF @p>54
SET @s=3;
ELSE IF @p>44
SET @s=2;
ELSE
SET @s=1;
SELECT @s;
) AS Degree
FROM Tablo_Person;
You cannot use a
DECLAREstatement within aSELECTquery like that. However, you can achieve the result by using aCASEexpression instead ofDECLAREandIFstatements.