Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you Execute a SP in query analyzer?

Status
Not open for further replies.

NervousRex

Programmer
Sep 4, 2003
66
US
I believe its EXEC SP_Name correct me if i'm wrong

But how do you execute a SP in query analyzer that has parameters? Both Input and Output?
 
Exec PROCNAME Arg1,Arg2 etc

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
I assume when you say Arg1, Arg2 that these are declared above this line?

Lets assume i have a procedure that looks like:


CREATE PROCEDURE usp_Return_Appointment_Detail
@Appointment_Log_Id as bigint,
@Appointment_Number as varchar(10) OUTPUT


How would I call it and view the output?
 
exec usp_Return_Appointment_Detail
1000, --(@Appointment_Log_Id),
'12345' --(@Appointment_Number)

Tim
 
an example SP
[/code]
CREATE PROCEDURE sp_Gen_Random_Numbers
@i_From int,
@i_To int,
@i_Quantity int
AS
SET NOCOUNT ON
IF @i_To <= @i_From RETURN ( 0 )
CREATE TABLE #Temp (
ID int PRIMARY KEY CLUSTERED
)
WHILE @i_From <= @i_To


BEGIN
INSERT #Temp (ID) VALUES (@i_From)
SET @i_From = @i_From + 1
END
SET ROWCOUNT @i_Quantity
SELECT
ID
FROM
#Temp
WHERE
ID <> 0
ORDER BY
NEWID()
DROP TABLE #Temp
RETURN( 0 )
[/code]

has three input arguments start number end number and number of random numbers between start and end you want:
Code:
exec sp_Gen_Random_Numbers 1,49,6
--and
sp_Gen_Random_Numbers 1,49,6

return 6 numbers between 1 and 49.

hope this helps

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
If you are trying to access the output parameter value then, try this:

declare @OpParam as varchar(10)

exec usp_Return_Appointment_Detail 10, @OpParam output

print @OpParam

Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top