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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic SQL

Status
Not open for further replies.

bobby1977

Programmer
Sep 8, 2000
10
0
0
RO
Hi!

To obtain a value using dynamic SQL, in Oracle I used
EXECUTE IMMEDIATE 'SELECT name FROM emp WHERE empno = :no' INTO lcv_name USING lnv_empno
where:
lnv_empno variable with employee ID value
lcv_name variable filled after statement execution with employee name

In SQL Server i can execute almost any kind of strings, but I do not know how to obtain a value in an output variable

how can I invoke sp_executeSQL with string
'SELECT @lcv_name = name FROM emp WHERE empno = @lnv_empno'
?
I mean how can i declare param definition string to work with an input and an output param ?

Thank you !
 
Assuming you what a single value in a variable and not in a resultset...

<b>Create a procedure:</b>

Create Proc TestProcedure @EmployeeID int
@OutputValue varchar(30) OUTPUT
AS

SELECT @OutputValue = Name
FROM emp
WHERE empno = @EmployeeID

<b>Call the procedure:</b>

DECLARE @EmployeeName varchar(30)

EXEC TestProcedure 1234, @EmployeeName OUTPUT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top