存储过程里调用另一个存储过程的值

第一种:

USE [WMS]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[Sys_GetSysNo]
  @NoCode = N'D001'

SELECT 'Return Value' = @return_value

GO
 

第二种:创建一个临时表

create proc GetUserName
as
begin
    select 'UserName'
end

Create table #tempTable (userName nvarchar(50))
insert into #tempTable(userName)
exec GetUserName

select #tempTable

--用完之后要把临时表清空
drop table #tempTable--需要注意的是,这种方法不能嵌套

第三种:

DECLARE @return_status INT
DECLARE @cmdText nvarchar(4000)--nvarchar 很重要这个地方
SET @cmdText='SELECT @return_status=COUNT(0) FROM '+@tableNameAdd+' WHERE '+@whereField +'='+''''+@Ops+'''';   
execute sp_executesql @cmdText,N'@return_status int out',@return_status out;
print @return_status

原文地址:https://www.cnblogs.com/JuneZhang/p/1885667.html