I create a stored procedure in SQL Server:
ALTER PROCEDURE [dbo].[testChildren]
@Parent INT
AS
BEGIN
SET NOCOUNT ON;
WITH EntityChildren AS
(
SELECT
nname, nodeid, level, ncode, nparent
FROM
GrpItm
WHERE
nodeid = @Parent
UNION ALL
SELECT
e.nname, e.nodeid, e.level, e.ncode, e.nparent
FROM
GrpItm e
INNER JOIN
EntityChildren e2 ON e.nparent = e2.nodeid
)
SELECT COUNT(Level) AS [level]
FROM EntityChildren
END
How can I make each count level in row and named the row by level value like this:
| level 1 | level 2 | level 3 |
+---------+---------+---------+
| 2 | 3 | 1 |

dynamic-sqland use ofspexecute_sql.)