I'm hoping this is the right section to post this in.I'm having some issues with returning data correctly from a UDF. My database has a folder table where each folder has an id and a column with the id of it's parent folder. I've written the following UDF to recursively retrieve all of the folders and their children from a comma seperated list.ALTER FUNCTION [dbo].[GetChildFolders](@FolderIds nvarchar)RETURNS @ChildFolders TABLE ( sid_folder_id int NOT NULL, dim_folder_parentid int NOT NULL)ASBEGIN WITH myFolders(sid_folder_id, dim_folder_parentid) AS( SELECT sid_folder_id, dim_folder_parentid FROM dbo.Split(@FolderIds,',') INNER JOIN dbo.Folder on sid_folder_id = data UNION ALL SELECT tpc.sid_folder_id, tpc.dim_folder_parentid FROM dbo.folder tpc WITH(NOLOCK) INNER JOIN myFolders ON myFolders.sid_folder_id = tpc.dim_folder_parentid ) INSERT INTO @ChildFolders SELECT * FROM myFolders; RETURNEND
If I run this as a query, it returns correctly. However in the UDF it only returns 1 row with bad data.