簡體   English   中英

SQL合並輸出子句錯誤

[英]SQL Merge Output Clause Error

我有三個表:

  1. 源表
  2. ODS表
  3. 登台表

我的merge語句使用源表將數據插入到ODS中,將輸出插入到暫存表中。 插入后,源表和ODS的計數相同,但是,登台計數小於兩者。 應該使用output子句將在ODS中插入的內容的副本插入到Staging中,但事實並非如此。 有人知道為什么會這樣嗎? 我的合並語句如下:

BEGIN TRANSACTION
BEGIN TRY
/* truncate staging table */
TRUNCATE TABLE stage table 

/* merge into ODS based on NK */
MERGE INTO ODS table as TRG
USING source table as SRC
/* ON Natural Key for that table/data type */
    ON TRG.column = SRC.column

/* insert new records into ODS */
WHEN NOT MATCHED AND SRC.column = @LOB THEN
    INSERT (columns )
    VALUES ( columns )

OUTPUT INSERTED.* INTO STG. table

COMMIT TRANSACTION

謝謝!

您可能需要;

BEGIN TRANSACTION

BEGIN TRY
/* truncate staging table */
TRUNCATE TABLE stage table ;

/* merge into ODS based on NK */
MERGE INTO ODS table as TRG
USING source table as SRC
/* ON Natural Key for that table/data type */
    ON TRG.column = SRC.column

/* insert new records into ODS */
WHEN NOT MATCHED AND SRC.column = @LOB THEN
    INSERT (columns )
    VALUES ( columns )

OUTPUT INSERTED.* INTO STG.table;

COMMIT TRANSACTION;

合並文檔

MERGE語句需要使用分號(;)作為語句終止符。


OUTPUT INSERTED.* INTO STG.table;OUTPUT INSERTED.* INTO STG.table; 是巨大的反模式, *而不是定義列列表

output inserted.col1, inserted.col2 INTO stg.table(col1_name, col2_name)

SQL合並輸出子句錯誤

問題在於變量@LOB是一個存儲過程變量,因此每當我通過LOB運行存儲過程時,它都會截斷先前LOB數據的臨時表,因此為什么該臨時表的數據少於源表和目標表的數據。現在解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM