use tempdb
GO
DROP TABLE IF EXISTS #Temp
CREATE TABLE #Temp
(
ID int IDENTITY(1,1),
Data char(1) null
)
INSERT INTO #Temp VALUES
('1') , (null) , (null) ,
('5') , (null) , (null) ,
('8') , (null) , (null)
SELECT * ,
SUM(IIF(Data IS NULL , 0 , 1)) OVER
(
ORDER BY ID
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS GroupNo
FROM #Temp
沒有留言:
張貼留言