How to create a function/method which counts how may files are within a particular folder - T-SQL

Solution 1:

Seems that you could use a JOIN from the table onto itself to achieve this. Something like this:

SELECT D.FullPath,
       D.[Type],
       COUNT(F.FullPath) AS Files
FROM dbo.YourTable D
     LEFT JOIN dbo.YourTable F ON F.FullPath LIKE D.FullPath + '%'
                              AND F.[Type] = 'File'
WHERE D.[Type] = 'Folder'
GROUP BY D.FullPath,
         D.[Type];