sqlserver 函數執行動態sql語句,取值

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;

posted @ 2014-10-14 11:43  文艺流浪汉  阅读(206)  评论(0编辑  收藏  举报