CREATE PROCEDURE p_myProcedure @NamePwdMi varchar (16),@NamePwdKey varchar (8),@NameProidMi varchar (16) output ,@NameProidKey varchar (8) output
AS
begin
declare @NPCol varchar(10)
declare @NGCol varchar(14)
declare @userId intselect @NPCol=NamePwdcol,@NGCol=NameProidcol ,@NameProidKey=NameProidKey from t_Key2Col where NamePwdkey=@NamePwdKeydeclare @sql nvarchar(1000)set @sql=N'select @userId=userId from t_NamePwdMi where NamePwdMi1='''+@NamePwdMi+N''''
execute sp_executesql @sql, N'@userId int output',@userId outputset @sql=N'select @NameProidMi=' + @NGCol + N' from t_NameProidMi where userId= @userId'
exec sp_executesql @sql , N'@NameProidMi varchar(16) output,@userId int' , @NameProidMi output, @userId end
GO
AS
begin
declare @NPCol varchar(10)
declare @NGCol varchar(14)
declare @userId intselect @NPCol=NamePwdcol,@NGCol=NameProidcol ,@NameProidKey=NameProidKey from t_Key2Col where NamePwdkey=@NamePwdKeydeclare @sql nvarchar(1000)set @sql=N'select @userId=userId from t_NamePwdMi where NamePwdMi1='''+@NamePwdMi+N''''
execute sp_executesql @sql, N'@userId int output',@userId outputset @sql=N'select @NameProidMi=' + @NGCol + N' from t_NameProidMi where userId= @userId'
exec sp_executesql @sql , N'@NameProidMi varchar(16) output,@userId int' , @NameProidMi output, @userId end
GO
declare @NPCol varchar(10)
declare @NGCol varchar(14)
where userId= @userId'