IN/OUT Problem | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

IN/OUT Problem

Dear ALL, How to simulate IN/OUT together in stored procedures(while passing parameters). Rajendar ok
Add the "output" keyword next to the parameter you are passing in. In the stored procedure you can select values to these paraameters and they will be returned.
Example in QA:
————– DECLARE @dataVARCHAR(255)
DECLARE @autoIDINT SELECT @data = ‘mydata’ EXEC InsertData @data, @autoID OUTPUT PRINT ‘Auto ID: ‘ + CONVERT(VARCHAR(10), @autoID) SP doing some insert returning an identity value:
————————————————- CREATE PROCEDURE InsertData
(
@dataVARCHAR(255),
@autoIDINT OUTPUT
)
AS
BEGIN
SET NOCOUNT ON INSERT INTO MyTable(
data,
dataDate
)
VALUES (
@data,
GETDATE()
) — Get auto generated ID
SELECT @autoID = SCOPE_IDENTITY() RETURN
END
/Argyle
Did you mean using the same parameter as both an input and output parameter? The example above shows the AutoID argument as an OUTPUT parameter. Nathan H.O.
Moderator
SQL-Server-Performance.com
You can use the same parameter as input and output paramter. Pass some value in the parmeter declared as OUTPUT and then pass the changed value from the called procedure to calling procedure. Gaurav
Moderator
Man thrives, oddly enough, only in the presence of a challenging environment- L. Ron Hubbard

yah!!!I mean using the same parameter as both an input and output parameter like in ORACLE (IN/OUT) together) Rajendar ok
Here you go….. CREATE PROC ExampleProc @InOutParam varchar(10) OUTPUT
AS
SET NOCOUNT ON
UPDATE MyTable SET [email protected]
SELECT MyOtherField as @InOutParam from MyTable
GO DECLARE @Param varchar(10)
SET @Param=1
EXEC ExampleProc @Param OUTPUT
Print @Param GO Nathan H.O.
Moderator
SQL-Server-Performance.com
]]>