https://www.cnblogs.com/zhchsh/p/9087292.html
--drop procedure zcstest;
create procedure zcstest
(
@tableName varchar(max),
@dataCount int output
)
as
declare @paramName varchar(max)
set @tableName = LTRIM(@tableName)
if @tableName is null or @tableName = ''
begin
set @paramName = '@tableName'
goto ArgumentNullException
end
declare @finalSql varchar(max)
declare @getCountSql nvarchar(max)
set @getCountSql = N'select @dataCount=count(*) from ' + @tableName
exec sp_executesql @getCountSql, N'@dataCount int output', @dataCount output
set @finalSql = 'select * from ' + @tableName
exec(@finalSql)
print(@finalSql)
return 0
ArgumentNullException:
raiserror('参数%s的值不能为空', 10, 1, @tableName)
return -60001
declare @dataCount int
exec [LCMDM9999].[zcstest] 'MDMWLDW',@dataCount output
print(@dataCount)