我有这个存储过程,你可以看到
create PROCEDURE [dbo].[SPViewMTOByLineIdAndTestPackageId]
@PackId int
AS
BEGIN
SELECT
*,
ISNULL(dbo.ReturnShortageByItemCodeLinePackage(LineId, TestPackageId, MaterialDescriptionId), 0) AS Shortage,
ISNULL(dbo.ReturnTotalIMIVByLineIdAndTestPackIdAndMaterialDescriptionId(LineId, TestPackageId, MaterialDescriptionId), 0) AS totalIMIV,
ISNULL(dbo.ReturnTotalMIVByLineIdAndTestPackIdAndMaterialDescriptionId(LineId, TestPackageId, MaterialDescriptionId), 0) AS TotalMIV,
ISNULL(dbo.ReturnTotalMRCByLineIdAndTestPackIdAndMaterialDesriptionId(LineId, TestPackageId, MaterialDescriptionId), 0) AS TotalMRC,
ISNULL(dbo.WarehouseByMaterialdesciptionId(MaterialDescriptionId), 0) AS Warehouse
FROM
dbo.ViewMTO
WHERE
TestPackageId = @PackId
如您所见,此存储过程接受输入并返回一些值。我想从另一个存储过程select statement
调用此存储过程来获取如下值:
CREATE PROCEDURE secondSP
AS
declare @a nvarchar(max)
BEGIN
select @a = shortage
from SPViewMTO(1) // The input value @PackId is 1 for example
END
答案 0 :(得分:0)
创建用于获取数据包信息的表值函数:
CREATE FUNCTION dbo.SPViewMTOByLineIdAndTestPackageId(@PackId int)
RETURNS @packInfo TABLE
(
Shortage int ,
totalIMIV int ,
TotalMIV int ,
JobTitle int ,
TotalMRC int
)
AS
-- Returns the first name, last name, job title, and contact type for the specified contact.
BEGIN
SELECT *,isnull(dbo.ReturnShortageByItemCodeLinePackage(LineId,TestPackageId,MaterialDescriptionId),0) As Shortage
,isnull(dbo.ReturnTotalIMIVByLineIdAndTestPackIdAndMaterialDescriptionId(LineId,TestPackageId,MaterialDescriptionId),0) as totalIMIV
,isnull(dbo.ReturnTotalMIVByLineIdAndTestPackIdAndMaterialDescriptionId(LineId,TestPackageId,MaterialDescriptionId),0) as TotalMIV
,isnull(dbo.ReturnTotalMRCByLineIdAndTestPackIdAndMaterialDesriptionId(LineId,TestPackageId,MaterialDescriptionId),0) as TotalMRC
,isnull(dbo.WarehouseByMaterialdesciptionId(MaterialDescriptionId),0) As Warehouse
from
dbo.ViewMTO where TestPackageId=@PackId
END
修改你的第二个程序如下:
Create PROCEDURE secondSP
AS
declare @a nvarchar(max)
BEGIN
select @a=shortage from dbo.SPViewMTOByLineIdAndTestPackageId(1)
END