Home All Groups Group Topic Archive Search About

Execute Stored Procedure Using Select Statement As Parameters

Author
26 Jan 2006 5:22 PM
Jig
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

Author
26 Jan 2006 5:31 PM
Edgardo Valdez, MCSD, MCDBA
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
Author
26 Jan 2006 6:56 PM
Mike
Could you be more specific on what you want to reach.

AddThis Social Bookmark Button