Forum Discussion

mtomova's avatar
mtomova
Helper III
1 year ago
Solved

Unable to use user defined table SQL Function in a SQL script in Fabric

Hi all,   I have a user defined table SQL Function created in Fabric. The function works fine when I use it on it's own and I pass the parameters.   However, when I try to nest it in another SQL ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi mtomova,

     

    Thank you for reaching out to Microsoft Fabric Community Forum.

     

    The issue happens because the user-defined table-valued function (CountWorkingDays) is placed inside a subquery in the SELECT clause. In Microsoft Fabric, this means the function runs separately for every single row in the dataset, which can slow things down massively and even make the query run indefinitely.


    Azure Synapse is designed to handle these kinds of function calls more efficiently, optimizing them in the execution plan. Fabric, on the other hand, doesn’t optimize them in the same way, which leads to performance issues.


    Instead of using the function inside a subquery, a better approach is to use CROSS APPLY. This helps the function return multiple rows for each input row in a much more optimized way. It processes data in sets rather than row by row, making the query run faster and more efficiently.


    If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!


    Regards,
    Vinay Pabbu