web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Using SQL Structured P...
Power Automate
Suggested Answer

Using SQL Structured Procedure performance.

(0) ShareShare
ReportReport
Posted on by 3,340
I have a structured procedure that works great in SQL SMSS.  The execution takes around 5 seconds.  When I invoke the procedure from powerapps, through a SQL structured procedure action, the run-time varies from 5s to several minutes.  Same data in and out.  The SQL server is VERY lightly loaded, in fact there may not be anyone at all using the sever when I'm invoking the procedure.  Why is there such a wide variance in performance?   
 
This procedure is quite simple.  It takes a long text string of numbers separated by a comma, creates a table from this, then joins with a view in SQL.  The resulting table is the desired result.  
[dbo].[FilterByPartNumbers]
    @PartNumbers NVARCHAR(MAX)
AS
BEGIN
    SET NOCOUNT ON;

    -- Create a temporary table for parsed part numbers
    CREATE TABLE #ParsedPartNumbers (
        PartNumber NVARCHAR(255) COLLATE Latin1_General_CI_AS_KS_WS NOT NULL PRIMARY KEY
    );

    -- Populate the temporary table
    INSERT INTO #ParsedPartNumbers (PartNumber)
    SELECT DISTINCT TRIM(value) COLLATE Latin1_General_CI_AS_KS_WS
    FROM STRING_SPLIT(@PartNumbers, ',');

    -- Select data directly from dbo.View_all_pdm_latest_pa
    SELECT 
        pp.PartNumber,
        v.*,
        CASE 
            WHEN v.PartNumber IS NULL THEN 1
            ELSE 0
        END AS Acc_Only
    FROM #ParsedPartNumbers pp
    LEFT JOIN dbo.View_all_pdm_latest_pa v
        ON pp.PartNumber = v.PartNumber COLLATE Latin1_General_CI_AS_KS_WS;

    -- Drop the temporary table
    DROP TABLE #ParsedPartNumbers;

    SET NOCOUNT OFF;
END;
Flow action:
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at
    Are you able to run an SQL trace to see what is taking that long for SQL server to respond.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard