我想将100k +行导入SQL Server表。
我有这样的插入(观察第6个子查询值):
INSERT INTO BD_S3I.dbo.AGENDA
(COD_UNDFBR, COD_DCPLNA, COD_TECNCA, COD_ATVIDE, DAT_PROGM_AGENDA, NUM_SQNCL_AGENDA, DAT_FINAL_AGENDA, COD_OCORR, COD_ROTA, NUM_SEMAN_PRGINS, NUM_DIAIN_PRGINS, DAT_INIC_PRGINS, MRC_SITUA_AGENDA, DAT_SUSPN_AGENDA, DAT_CONCL_AGENDA, DAT_REPRG_AGENDA, DCR_SITUA_AGENDA, DCR_AGENDA, MRC_AVISO_AGENDA, MRC_NEGLG_AGENDA, NUM_PERIO_PRGINS, DAT_DIAIN_PRGINS, DAT_JUSTN_AGENDA, COD_MTVNVS, MRC_ERP_AGENDA, COD_USUS3I_JUSTN)
VALUES
(1, 290, 2, 6, '2017-09-11 00:00:00.000', (SELECT CASE WHEN MAX(AGENDA.NUM_SQNCL_AGENDA) + 1 IS NULL THEN 1 ELSE MAX(AGENDA.NUM_SQNCL_AGENDA) + 1 END FROM AGENDA WHERE AGENDA.COD_UNDFBR = 1 AND AGENDA.COD_DCPLNA = 290 AND AGENDA.COD_TECNCA = 2 AND AGENDA.COD_ATVIDE = 6 AND AGENDA.DAT_PROGM_AGENDA = '2017-09-11 00:00:00.000'), '2017-09-17 00:00:00.000', NULL, 492, NULL, NULL, '2017-07-24 08:30:00.000', 'P', NULL, NULL, NULL, NULL, NULL, 'S', 'S', 7, '2017-07-24 00:00:00.000', NULL, NULL, 'N', NULL);
我将100k插入物放在彼此之下并开始导入。它工作正常,但是花费太多时间来执行所有100k +行。
我在考虑使用导入向导(时间更好?)。
问题是当我选择带有我的数据的excel文件时,导入向导不理解该值的子查询。它称之为长篇大论。
答案 0 :(得分:0)
选择至少一个需要插入第6列的返回类型。 就像
( SELECT x = CASE .... )
或者在最后使用返回类型和子查询。
答案 1 :(得分:0)
只需将您的INSERT...VALUES
转换为INSERT...SELECT
即可,因为所有其他值都是标量,并且可以与子查询的SELECT
语句一起包含在内:
INSERT INTO BD_S3I.dbo.AGENDA (COD_UNDFBR, COD_DCPLNA, COD_TECNCA, COD_ATVIDE,
DAT_PROGM_AGENDA, NUM_SQNCL_AGENDA, DAT_FINAL_AGENDA,
COD_OCORR, COD_ROTA, NUM_SEMAN_PRGINS, NUM_DIAIN_PRGINS,
DAT_INIC_PRGINS, MRC_SITUA_AGENDA, DAT_SUSPN_AGENDA,
DAT_CONCL_AGENDA, DAT_REPRG_AGENDA, DCR_SITUA_AGENDA,
DCR_AGENDA, MRC_AVISO_AGENDA, MRC_NEGLG_AGENDA,
NUM_PERIO_PRGINS, DAT_DIAIN_PRGINS, DAT_JUSTN_AGENDA,
COD_MTVNVS, MRC_ERP_AGENDA, COD_USUS3I_JUSTN)
SELECT 1, 290, 2, 6, '2017-09-11 00:00:00.000',
CASE WHEN MAX(AGENDA.NUM_SQNCL_AGENDA) + 1 IS NULL
THEN 1
ELSE MAX(AGENDA.NUM_SQNCL_AGENDA) + 1
END,
'2017-09-17 00:00:00.000', NULL, 492, NULL,
NULL, '2017-07-24 08:30:00.000', 'P',
NULL, NULL, NULL, NULL, NULL, 'S', 'S', 7,
'2017-07-24 00:00:00.000', NULL, NULL, 'N', NULL
FROM AGENDA
WHERE AGENDA.COD_UNDFBR = 1 AND AGENDA.COD_DCPLNA = 290
AND AGENDA.COD_TECNCA = 2 AND AGENDA.COD_ATVIDE = 6
AND AGENDA.DAT_PROGM_AGENDA = '2017-09-11 00:00:00.000')