sp_executesql Demo

 

create procedure GetcountBytable
@table sysname
as
declare @Count int
declare @sql nvarchar(1000)
set @sql='select @Count=count(*) from ' + @table
exec sp_executesql @sql,N'@Count int out',@Count out
return (@count)

 

declare @i int
exec @i=GetcountBytable 'sysobjects'
select @i

 

你可能感兴趣的:(execute)