How do I pass a value from one stored procedure to another in SQL?

How do I pass a value from one stored procedure to another in SQL?

Passing value from one Stored Procedure to another

  1. @TimeStamp DATETIME.
  2. SET @TimeStamp = DATEADD(MM, -1, CAST(FLOOR( CAST( GETDATE() AS FLOAT ) )AS DATETIME))
  3. EXEC sp_storedproc2 @TimeStamp.
  4. DELETE FROM Table2 WHERE [Date] < @TimeStamp.

How do you pass data into a stored procedure?

Passing Data table as Parameter to Stored Procedures

  1. Create a user-defined table type that corresponds to the table that you want to populate.
  2. Pass the user-defined table to the stored procedure as a parameter.

How can use multiple output parameter in stored procedure?

In order to fetch the multiple returned values from the Stored Procedure, you need to make use of a variable with data type and size same as the Output parameter and pass it as Output parameter using OUTPUT keyword. You can also make use of the Split function to split the comma separated (delimited) values into rows.

How to pass one stored procedure to another?

SQL SERVER – Pass One Stored Procedure’s Result as Another Stored Procedure’s Parameter. This is one of the most asked questions related to stored procedure (SP) in recent time and the answer is even simpler.

When to use output directive in second stored procedure?

As Gordon wrote in the comments, You could have an output parameter on the second stored procedure. another option would be to use rahul ‘s example (if the second stored procedure simply returns a scalar value) in the first stored procedure you should use the output directive when executing the second procedure:

Which is another stored procedure with the following statement inside?

Which calls another stored procedure with the following statement inside: However when I test the call the EXEC outputs the value correctly but it is not assigned to the @Count parameter correctly. I’ve seen examples or stored procedures used like this, including here but none had a parameter and a return value used (that I could find).

How to assign values to a stored procedure?

Make sure you assign some values to output params in your stored procedure. CREATE PROCEDURE [dbo].