Monday, 19 August 2013

DYNAMIC SQL

-------------DYNAMIC SQL----------------

alter proc emp_ins (@name varchar(100) , @empno int out )
as
 begin
 declare @query nvarchar(500)=( 'select @i_empno=empno from emp where ename =@in_name ')
 exec sp_executesql @query,N'@in_name varchar(100),@i_empno int out'  ,@in_name=@name,@i_empno=@empno out
end
 
 
declare @c int
exec emp_ins 'smith',@c out

print @c

No comments:

Post a Comment

EMP, DEPT Sample script

/****** Object:  Table [dbo].[DEPT]    Script Date: 19-05-2016 06:58:37 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET A...