DECLARE @tbl TABLE (
Subsection NVARCHAR(500)
,RowNo INT
)
INSERT INTO @tbl (
Subsection
,RowNo
)
SELECT s.Subsection
,ROW_NUMBER() OVER (
ORDER BY (
SELECT NULL
)
) AS rn
FROM dbo.Sheet1$ s
SELECT *
FROM @tbl
SELECT t.Subsection
,max(t.RowNo)
,ROW_NUMBER() OVER (
ORDER BY (
SELECT NULL
)
) AS rn
FROM @tbl t
GROUP BY t.Subsection
ORDER BY 2
--SELECT * FROM dbo.HierarchyMaster hm WHERE hm.ParentId = 104
--SELECT * FROM dbo.HierarchyMaster hm WHERE hm.LevelId = 3
--DECLARE @maxOrder nvarchar(200)
--SELECT @maxOrder= convert(nvarchar(100), max(hm.OrderNo)) FROM dbo.HierarchyMaster hm WHERE hm.LevelId = 3