|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Execute Stored Procedure Using Select Statement As ParametersHi,
I'm trying to run a SP with a select statement. Example below: Stored procedure: uspI_InsertUsername (@Username VARCHAR(50)) SQL Statement: EXEC uspR_InsertUsername SELECT Username FROM TempUser Will this work? -- Thanks, Jig Patel You can store the result of the query to a temporary variable and execute the
sp using the result declare @user VARCHAR(50) select @user = Username FROM TempUser EXEC uspR_InsertUsername @user it will work when select Username FROM TempUser returns only one user, otherwise you will have to declare @user as a table variable and loop through it to execute the procedure for each row Let me know if it helps Show quote "Jig" wrote: > Hi, > > I'm trying to run a SP with a select statement. Example below: > > Stored procedure: uspI_InsertUsername (@Username VARCHAR(50)) > > SQL Statement: EXEC uspR_InsertUsername SELECT Username FROM TempUser > > Will this work? > -- > Thanks, > > Jig Patel |
|||||||||||||||||||||||