SQL此问题表为空但存储过程成功时

时间:2018-11-01 14:56:05

标签: sql-server stored-procedures

我有一个问题:此存储过程成功完成后出现问题,但是表中所有列均为空,表为空,但存储过程成功。

USE [database]   
GO

/****** Object:  StoredProcedure [dbo].[exampleprocedur]    Script Date: 1.11.2018 17:32:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[exampleprocedur]
AS
BEGIN
    DELETE FROM [database].dbo.exampletable

    CREATE TABLE #examplecode 
    (
         colon1 VARCHAR(120),
         colon2 VARCHAR(120),
         colon3 VARCHAR(120),
         colon4 VARCHAR(120),
         colon5 VARCHAR(120),
         colon6 VARCHAR(120),
         colon7 VARCHAR(120),
         colon8 DECIMAL(28, 5),
         colon9 DECIMAL(28,5)
    )

    INSERT INTO #examplecode 
        SELECT
             a.colon1_no, a.colon2_no, a.colon3, '', '', '', '',
             a.colon8, a.colon9 
         FROM
             [database2].dbo.expr a (nolock) 
         WHERE
             colon2_no = '100'  
         ORDER BY
             a.colon3  

    SELECT * 
    INTO #examplecode2 
    FROM
        (SELECT
             b.colon3, b.colon11, b.colon12 
         FROM
             [database2].dbo.mmm b 
         WHERE
             colon11 IN ('ver1', 'ver2', 'ver3', 'ver4') 
             AND EXISTS (SELECT a.colon3 FROM #examplecode a 
                         WHERE a.colon3 = b.colon3)) tablom
    PIVOT
        (MAX(colon12)
            FOR colon11 IN ([ver1],[ver2],[ver3],[ver4])
        ) pivottablom

    UPDATE a 
    SET a.colon4 = b.colon4,
        a.colon5 = b.colon5,
        a.colon6 = b.zx,
        a.colon7 = b.zy 
    FROM 
        #examplecode a, #examplecode2 b 
    WHERE
        a.colon3 = b.colon3

    UPDATE a 
    SET a.colon2 = b.colon2_adi,
        a.colon1 = b.colon1_adi 
    FROM
        #examplecode a, [database2].dbo.mlz_colon1_colon2 b 
    WHERE
        a.colon2 = b.colon2_no 
        AND a.colon1 = b.colon1_no 

    INSERT INTO [database].dbo.exampletable(ver1Kodu, ver2, Em, ver3, ver4, Tm)
        SELECT
            colon4, SUBSTRING(colon5, 1, 7), colon8, colon6, colon7, 1 
        FROM
            #examplecode 
        WHERE
            colon4 IN ('1000') AND colon9 != 0.00000

    UPDATE [database].dbo.exampletable 
    SET ver2 = REPLACE(ver2, 'x', ' X ');

1 个答案:

答案 0 :(得分:1)

执行存储过程而没有错误并不意味着它会插入数据,这仅意味着没有语法错误,在您的代码中,您将删除exampletable中的所有数据,并且插入发生在where条件下,因此没有满足您条件的数据,因此没有插入任何内容