I have a CTE as below (logic removed)
;with cte_a as
(
select ID, Count(AnotherID) as Counter
from Table_A
group by ID
)
and a user defined function that takes an Id as input and returns a table.
udf_GetRelatedItemIds(@Id)
I wanted to just count the number of related item ids returned from the user defined function for each ID in cte_a.
I was trying something like below but it didn't work
;with cte_a as
(
select ID, Count(AnotherID) as Counter
from Table_A
group by ID
)
select
ID,
Count(select RelatedId from udf_GetRelatedItemIds(ID))
from cte_a
Please suggest a solution.