declare @sql nvarchar(4000)
declare @username nvarchar(20)
begin
set @sql =‘select @username=Name from(
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm) A ‘
exec sp_executesql @sql,N‘@username nvarchar(20) output‘,@username output
select @username
end;