首页 > 代码库 > sqlserver 函數執行動態sql語句,取值

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;

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