2016-10-06 3 views
-1

Ich habe diese gespeicherte Prozedur SieErhalten Sie als den Wert einer gespeicherten Prozedur in einer anderen gespeicherten Prozedur mit ausgewählten

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 

sehen können, wie Sie einen Eingang sehen können, übernimmt diese gespeicherte Prozedur und einige Werte zurückgeben. Ich möchte mit select statement diese gespeicherte Prozedur von einer anderen gespeicherten Prozedur aufrufen, die Werte wie folgt zu erhalten:

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

Prozedur kann nicht verwendet werden, wie Sie haben. Verwenden Sie stattdessen eine Tabellenwertfunktion –

+0

@AksheyBhat Store-Prozedur in Tabellenfunktion aufrufen? –

+0

Youg ändern Verfahren in einem anderen Verfahren ?? Nein, Sie können SP nicht innerhalb von Funktionen verwenden. – gofr1

Antwort

0

einen Tabellenwert-Funktion erstellen für das Erhalten Paketinfo:

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 [email protected] 
    END 

Ändern Sie bitte Ihre zweite proc wie unten :

Create PROCEDURE secondSP 
    AS 
    declare @a nvarchar(max) 
    BEGIN 

      select @a=shortage from dbo.SPViewMTOByLineIdAndTestPackageId(1) 

    END 
Verwandte Themen