I have a table with several children. Any child can meet several times, and there is a column βEventsβ that contains this number, so the data in the table looks something like this:
ChildID | ParentID | Occurences ------------------------------- 1 | 1 | 2 2 | 1 | 2 3 | 2 | 1 4 | 2 | 3
I need to get a list of all the children, each of which displays the number of times as a result, something like
IDENT | ChildID | ParentID -------------------------- 1 | 1 | 1 2 | 1 | 1 3 | 2 | 1 4 | 2 | 1 5 | 3 | 2 6 | 4 | 2 7 | 4 | 2 8 | 4 | 2
I can do this with a cursor that processes the table and inserts as many rows as necessary, but I don't think this is the best solution.
thanks for the help
Create the script bundled:
DECLARE @Children TABLE (ChildID int, ParentID int, Occurences int) INSERT @Children SELECT 1, 1, 2 UNION ALL SELECT 2, 1, 2 UNION ALL SELECT 3, 2, 1 UNION ALL SELECT 4, 2, 3
source share