if object_id('finaltest') is not null
drop proc finaltest
go
create proc finaltest
@student_number INT output,
@lastfirst varchar(50) output,
@input_grade int
as
declare @sql NVARCHAR(500)
set @sql=N'select @p=student_number,@q=lastfirst from students where grade_level=@i'
exec sp_executesql @sql,N'@p int output,@q varchar(50) output,@i int',
@p=@student_number output ,
@q=@lastfirst output,
@i=@input_grade
select @student_number,@lastfirst,@input_grade,@sql
go
---------------------------------------------below is out side--------------------------------------------------------
declare @student_number_out int,
@lastfirst_out varchar(50)
exec finaltest
@student_number=@student_number_out output,
@lastfirst=@lastfirst_out output,
@input_grade=9
select @student_number_out,@lastfirst_out
go