Get inserted ID in an Execute non query activity

I’m writing to a MS SQL database and in that instance I need to get the inserted ID returned.

I need something like this:

INSERT INTO table (name)
OUTPUT Inserted.ID
VALUES('bob');

Please help.

Insert query returns the number of inserted rows into a table.
I am not sure if that is yet supported in the uipath.

Run another query (Execute query)

SELECT SCOPE_IDENTITY()

To get the recently inserted ID.

Regards,
Karthik Byggari

1 Like

I would really like to avoid 2 queries, because if we are running on multiple robots then we might get an issue getting the actual inserted ID.

Thanks!

This is the supported output as per the documentation -

Output

  • AffectedRecords - The result of the execution of the sql command. For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.

You should create parameterised query to get the output.

Regards,
Karthik Byggari

Thanks KarthikByggari,

Do you have an example? I can’t make the parameters work.

Regards

Leif

These parameters works if you are running the stored procedure.
In your case, you have to create a stored procedure with IN and OUT parameters.

Regards,
Karthik Byggari

1 Like

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