SQL Stored procedure Passing Parameters To fetch particular records

How Should I fetch particular records from Stored Procedure?
I am having difficulty to pass parameters.

In my Stored Procedure there are 3 invoice account number having sales order list.
I want to fetch separate records for each account number.

Anyone can help me on this?

Hi @pari_patel ,

Take a look at this to know the pass the parameters in the sql

Regards
Balamurugan.s

Sure. Thanks

1 Like

Hi @pari_patel,

I am assuming that you have set up your connection correctly using “Connect to DB” activity. The “Execute Query” activity takes the output of “Connect to DB” activity

"Connect to DB" ---> "Execute Query"

UiPath has a strict syntax requirement for parameters in the “Execute Query” activity (only takes String expressions).

  1. If your StoredProcedure takes in one parameter

    StoredProcedure = YourStoredProcedure
    Parameter for StoredProcedure = @YourRequiredParameter
    Variable from UiPath = inputAccountNumber → Set this as Input to Execute Query
    (Mind the quotes)
    The following expression is to be used in the Execute Query → Sql (as Input)

    "exec YourStoredProcedure @YourRequiredParameter="+"'"+inputAccountNumber+"'"
    
  2. If your StoredProcedure takes multiple parameters

    "exec YourStoredProcedure @YourRequiredParameter="+"'"+inputAccountNumber+"'"+","+"@YourRequiredParameter1="+"'"+inputAccountNumber1+"'"
    

The Challenge
You will have to explicitly cast the string you send from Execute Query to the datatype in your database. For example, if @YourAccountNumber is of integer type, you will have to edit the stored procedure to take string input and later when SQL executes the query in DB to cast the string parameter to integer and execute the query.

We have used this approach with upto 5 parameters and the Execute Query activity performs great on an onpremises database.

Hope this helps you and others.

1 Like

Thank you so much

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.