How to Use 'Exec Sp_executesql' to Read SQL String with Data Exchange(Interface)

来源:互联网 发布:js怎样仿写shift 编辑:程序博客网 时间:2024/06/06 07:19

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 

1 0
原创粉丝点击