Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回SQL Server存储过程中最后选定的结果集_Sql_Stored Procedures_Sql Server 2012 - Fatal编程技术网

返回SQL Server存储过程中最后选定的结果集

返回SQL Server存储过程中最后选定的结果集,sql,stored-procedures,sql-server-2012,Sql,Stored Procedures,Sql Server 2012,我只需要一个结果选择表作为存储过程的输出,以便在节点red flow中使用它将其传递给另一个函数。因为我有两个选择,第一个选择用于游标迭代,它还产生了一个out for存储过程,我实际上从存储过程输出中去掉了它。这件事我已经坚持了三天了 CREATE PROCEDURE [dbo].[GetOrderStartingLevel] @joborder nvarchar(100) AS BEGIN SET NOCOUNT ON; IF OBJECT_ID('tempdb.

我只需要一个结果选择表作为存储过程的输出,以便在节点red flow中使用它将其传递给另一个函数。因为我有两个选择,第一个选择用于游标迭代,它还产生了一个out for存储过程,我实际上从存储过程输出中去掉了它。这件事我已经坚持了三天了

CREATE PROCEDURE [dbo].[GetOrderStartingLevel] 
    @joborder nvarchar(100)
AS
BEGIN
    SET NOCOUNT ON;

    IF OBJECT_ID('tempdb.dbo.#TempTable', 'U') IS NOT NULL
        DROP TABLE #TempTable;

    IF OBJECT_ID('tempdb.dbo.#Degerler', 'U') IS NOT NULL
        DROP TABLE #Degerler;

    CREATE TABLE #TempTable 
    (
        siparis nvarchar(100),
        TotalCopies int,
        GoogCopies int,
        PoweredTime int,
        zaman datetime
    )

    CREATE TABLE #Values
    (
        siparis nvarchar(100),
        zaman datetime,
        totalcopies int, 
        googcopies int,
        PoweredTime int,
        GoodCopiesTime int, 
        ChangingTime int,
        Preparation int
    )

    INSERT INTO #TempTable
        SELECT
            [siparis], [TotalCopies], [GoogCopies],
            PoweredTime, zaman    
        FROM 
            [KurumsalZEKA].[dbo].[GunlukUretim]
        WHERE 
            siparis LIKE @joborder

    DECLARE @zaman datetime
    DECLARE @olddate datetime
    DECLARE @totalcopies int
    DECLARE @currentcopies int
    DECLARE @poweredtime int
    DECLARE @currentpoweredtime int

    SET @currentcopies = 0

    SELECT * 
    FROM #TempTable

    DECLARE cur CURSOR FOR 
        SELECT 
            zaman, totalcopies, PoweredTime 
        FROM 
            #TempTable 
        ORDER BY
            zaman ASC

    OPEN cur

    FETCH NEXT FROM cur INTO @zaman, @totalcopies, @poweredtime

    WHILE @@FETCH_STATUS = 0 
    BEGIN
        IF (@totalcopies - @currentcopies < 0) OR 
           (@currentpoweredtime - @poweredtime > 0)
            INSERT INTO #Values 
                SELECT
                    siparis, zaman, totalcopies, 
                    googcopies, PoweredTime, GoodCopiesTime, 
                    ChangingTime, Preparation 
                FROM 
                    dbo.GunlukUretim
                WHERE
                    zaman = @olddate;

        SET @currentcopies = @totalcopies
        SET @olddate = @zaman
        SET @currentpoweredtime = @poweredtime

        FETCH NEXT FROM cur INTO @zaman, @totalcopies, @poweredtime
    END

    CLOSE cur    
    DEALLOCATE cur

    INSERT INTO #Values  -- minimum deger
        SELECT TOP 1 
            siparis, zaman, totalcopies * (-1),
            googcopies * (-1),
            PoweredTime * (-1),
            GoodCopiesTime * (-1),
            ChangingTime * (-1),
            Preparation * (-1)  
        FROM
            dbo.GunlukUretim
        WHERE
            siparis LIKE @joborder 
        ORDER BY
            zaman

    INSERT INTO #Values   -- maximum deger
        SELECT TOP 1 
            siparis, zaman, totalcopies,
            googcopies, PoweredTime, GoodCopiesTime,
            ChangingTime, Preparation  
        FROM
            dbo.GunlukUretim
        WHERE
            siparis LIKE @joborder 
        ORDER BY 
            zaman DESC

    --select * from #Degerler
    IF OBJECT_ID('tempdb.dbo.#Degerler', 'U') IS NOT NULL
        SELECT
            MIN(zaman) AS start,
            MAX(zaman) AS finish,
            SUM(totalcopies) AS totalcopies,
            SUM(googcopies) AS goodcopies,
            SUM(PoweredTime) AS poweredtime,
            SUM(GoodCopiesTime) AS goodcopiestime,
            SUM(ChangingTime) AS changingtime, 
            SUM(Preparation) AS preparation 
        FROM 
            #Values 
        GROUP BY
            siparis;
END

标记您正在使用的dbms。该代码是特定于产品的。您希望选择哪个选项作为结果集?你们不能把SELECT*从诱惑中删除吗?是的,我完全错过了我用瞎眼看的,很抱歉这个愚蠢的问题。谢谢