通配符SQL Server Merge语句的语法

时间:2017-02-21 23:42:58

标签: sql sql-server merge

此SQL Server MERGE语句有效,但它很笨拙。是否有任何语法来合并这两个表,以便它们具有完全相同的结构?我正在尝试从Score_date表更新Score_Import。我有很多表要做,不想输出它们。谢谢。

MERGE INTO [Score_Data].[dbo].Product as Dp
  USING [Score_import].[dbo].Product as Ip
    ON Dp.part_no = Ip.part_no
WHEN MATCHED THEN
  UPDATE
    SET Dp.total = Ip.total
       ,Dp.description = Ip.description
       ,Dp.family = Ip.family
       ,DP.um = IP.um
       ,DP.new_part_no = IP.new_part_no
       ,DP.prod_code = IP.prod_code
       ,DP.sub1 = IP.sub1
       ,DP.sub2 = IP.sub2
       ,DP.ven_no = IP.ven_no
       ,DP.no_sell = IP.no_sell
       ,DP.rp_dns = IP.rp_dns
       ,DP.nfa = IP.nfa
       ,DP.loc = IP.loc
       ,DP.cat_desc = IP.cat_desc
       ,DP.cat_color = IP.cat_color
       ,DP.cat_size = IP.cat_size
       ,DP.cat_fits = IP.cat_fits
       ,DP.cat_brand = IP.cat_brand
       ,DP.cat_usd1 = IP.cat_usd1
       ,DP.cat_usd2 = IP.cat_usd2
       ,DP.cat_usd3 = IP.cat_usd3
       ,DP.cat_usd4 = IP.cat_usd4
       ,DP.cat_usd5 = IP.cat_usd5
       ,DP.cat_usd6 = IP.cat_usd6
       ,DP.cat_usd7 = IP.cat_usd7
       ,DP.cat_usd8 = IP.cat_usd8
       ,DP.cat_usd9 = IP.cat_usd9
       ,DP.cat_usd10 = IP.cat_usd10
       ,DP.cat_usd11 = IP.cat_usd11
       ,DP.cat_usd12 = IP.cat_usd12
       ,DP.cat_usd13 = IP.cat_usd13
       ,DP.cat_usd14 = IP.cat_usd14
       ,DP.cat_usd15 = IP.cat_usd15
       ,DP.buy = IP.buy
       ,DP.price_1 = IP.price_1
       ,DP.price_2 = IP.price_2
       ,DP.price_3 = IP.price_3
       ,DP.price_4 = IP.price_4
       ,DP.price_5 = IP.price_5
       ,DP.price_6 = IP.price_6
       ,DP.price_7 = IP.price_7
       ,DP.price_8 = IP.price_8
       ,DP.price_9 = IP.price_9
       ,DP.create_date = IP.create_date
       ,DP.barcode = IP.barcode
       ,DP.check_digit = IP.check_digit
       ,DP.supplier = IP.supplier
       ,DP.prc_fam_code = DP.prc_fam_code
       ,DP.note = IP.note
       ,DP.mfg_part_no = IP.mfg_part_no
       ,DP.special = IP.special
       ,DP.spc_price = IP.spc_price
       ,DP.firm = IP.firm
       ,DP.box = IP.box
       ,DP.no_split = IP.no_split
       ,DP.drop_ship = IP.drop_ship
       ,DP.case_pack = IP.case_pack
       ,DP.inner_pack = IP.inner_pack       
WHEN NOT MATCHED BY TARGET THEN
  INSERT (part_no
 ,description
 ,family
 ,Total
 ,um
 ,new_part_no
 ,prod_code
 ,sub1
 ,sub2
 ,ven_no
 ,no_sell
 ,rp_dns
 ,nfa
 ,loc
 ,cat_desc
 ,cat_color
 ,cat_size
 ,cat_fits
 ,cat_brand
 ,cat_usd1
 ,cat_usd2
 ,cat_usd3
 ,cat_usd4
 ,cat_usd5
 ,cat_usd6 
 ,cat_usd7
 ,cat_usd8
 ,cat_usd9
 ,cat_usd10
 ,cat_usd11
 ,cat_usd12
 ,cat_usd13
 ,cat_usd14
 ,cat_usd15
 ,buy
 ,price_1
 ,price_2
 ,price_3
 ,price_4
 ,price_5
 ,price_6,
 ,price_7,
 ,price_8
 ,price_9
 ,create_date
 ,barcode
 ,check_digit
 ,supplier
 ,prc_fam_code
 ,note
 ,mfg_part_no
 ,special
 ,spc_price
 ,firm
 ,box
 ,no_split
 ,drop_ship
 ,case_pack
 ,inner_pack)
  VALUES
 (Ip.Part_no
 ,Ip.description
 ,Ip.family
 ,Ip.Total
 ,Ip.um
 ,Ip.new_part_no
 ,Ip.prod_code
 ,Ip.sub1
 ,Ip.sub2
 ,Ip.ven_no
 ,Ip.no_sell
 ,Ip.rp_dns
 ,Ip.nfa
 ,Ip.loc
 ,Ip.cat_desc
 ,Ip.cat_color
 ,Ip.cat_size
 ,Ip.cat_fits
 ,Ip.cat_brand
 ,Ip.cat_usd1
 ,Ip.cat_usd2
 ,Ip.cat_usd3
 ,Ip.cat_usd4
 ,Ip.cat_usd5
 ,Ip.cat_usd6 
 ,Ip.cat_usd7
 ,Ip.cat_usd8
 ,Ip.cat_usd9
 ,Ip.cat_usd10
 ,Ip.cat_usd11
 ,Ip.cat_usd12
 ,Ip.cat_usd13
 ,Ip.cat_usd14
 ,Ip.cat_usd15
 ,Ip.buy
 ,Ip.price_1
 ,Ip.price_2
 ,Ip.price_3
 ,Ip.price_4
 ,Ip.price_5
 ,Ip.price_6
 ,Ip.price_7
 ,Ip.price_8
 ,Ip.price_9
 ,Ip.create_date
 ,Ip.barcode
 ,Ip.check_digit
 ,Ip.supplier
 ,Ip.prc_fam_code
 ,Ip.note
 ,Ip.mfg_part_no
 ,Ip.special
 ,Ip.spc_price
 ,Ip.firm
 ,Ip.box
 ,Ip.no_split
 ,Ip.drop_ship
 ,Ip.case_pack
 ,Ip.inner_pack)
WHEN NOT MATCHED BY SOURCE THEN
  DELETE
  OUTPUT $action, Inserted.*, Deleted.*; 

0 个答案:

没有答案