SQL Server 创建带返回值的存储过程


--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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM