Jeg tror, du kan bruge en forespørgsel som denne:
SELECT *,
CASE
WHEN Active <> 0 AND
ISNULL(LAG(Active) OVER (PARTITION BY LocationCode ORDER BY YearMonth), 0) = 0 THEN 1
ELSE 0
END As New
FROM yourTable;
Jeg tror, du kan bruge en forespørgsel som denne:
SELECT *,
CASE
WHEN Active <> 0 AND
ISNULL(LAG(Active) OVER (PARTITION BY LocationCode ORDER BY YearMonth), 0) = 0 THEN 1
ELSE 0
END As New
FROM yourTable;