I have the below select statement.
WITH cte AS
(
SELECT MAX(logDate) AS Daily
FROM PhysicalDriveSize
GROUP BY DATEADD(m, DATEDIFF(m, 0, logDate), 0)
)
SELECT CAST(MIN(t.logDate) AS DATE) AS [Date], Drive, MIN(t.Free) AS [PercentagFree]
FROM PhysicalDriveSize AS t
JOIN cte AS m
ON t.logDate = m.Daily
WHERE t.Free <= 10 AND t.Free >= 0
GROUP BY Drive, logDate
I want to do some actions based on the results for ex.
WITH cte AS
(
SELECT MAX(logDate) AS Daily
FROM PhysicalDriveSize
GROUP BY DATEADD(m, DATEDIFF(m, 0, logDate), 0)
)
SELECT MIN(t.Free) AS [PercentagFree]
FROM PhysicalDriveSize AS t
JOIN cte AS m
ON t.logDate = m.Daily
WHERE t.Free <= 10 AND t.Free >= 0
GROUP BY Drive, logDate
IF t.Free <= 10 AND t.Free >= 5
PRINT 'Warning'
Else
PRINT 'Critical'
I get the below error if I perform if statement:
Msg 4104, Level 16, State 1, Line 13 The multi-part identifier "t.Free" could not be bound. Msg 4104, Level 16, State 1, Line 13 The multi-part identifier "t.Free" could not be bound
how can I engage if statement without errors??