Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago

How to Execute Stored procedure using 2 dynamic parameter in Direct query Method

Hi Team,

 

In my project i have requirement to execute stored procedure using 2 dynamic parameter in Direct query method. I am able to execute the procedure using one parameter. But, when I try to execute 2 parameter i am getting error. 

Below is the screenshot of power M query code from advance editor. and error also attaching.

 

It would be really helpful if anyone of here can help me to fix this issue.

Thanks in advance.

 

 

 

 

 

5 Replies

  • count your single quotes. You are missing a couple and forgot to escape others.

    • Anonymous's avatar
      Anonymous
      Not applicable

      After checking all the quotes still i am getting the same error.

      let
          CompanyId = Text.From(P_COMPANY_ID),  // Ensure P_COMPANY_ID is defined
          PeriodRange = Text.From(periodRange),  // Ensure periodRange is defined
          EscapedPeriodRange = "'" & Text.Replace(PeriodRange, "'", "''") & "'",  // Escape single quotes in periodRange
          Query = "SELECT * FROM OPENROWSET('SQLNCLI','Server=.......\XportUAT;Trusted_Connection=yes;','EXEC Xport_UAT_NEW.dbo.USP_GET_PERIOD_DATA_FS_BY_PERIODRANGE_SH @pCompany_Id=" & CompanyId & ", @PeriodRange=" & EscapedPeriodRange & "')",
          Source = Sql.Database("......\XportUAT", "Xport_UAT_NEW", [Query=Query])
      in
          Source

      I tried new above code. Could you please let me know where i am doing mistake. it would be helpful if you can suggest me in detail.

      • lbendlin's avatar
        lbendlin
        Super User

        what's the purpose of 

         

        SELECT * FROM OPENROWSET

         ?  

         

        Looks like your SP is not even part of the query.