Sql 基于多列,将staging表追加到main时,会出现大量空值

Sql 基于多列,将staging表追加到main时,会出现大量空值,sql,ms-access,Sql,Ms Access,将会计系统中的行带入暂存表。要将临时表中的新REC追加到主表中。没有主键,因为除了查看每一列之外,行中没有唯一标识符。很多空值,因为不是每一列都需要填写 示例数据: Staging: budget_line|date |fund|amount|description|PO_number 1 |20140623 |xyz |12.00 |donut |{null} 1 |{null} |xyz |3.00 |{

将会计系统中的行带入暂存表。要将临时表中的新REC追加到主表中。没有主键,因为除了查看每一列之外,行中没有唯一标识符。很多空值,因为不是每一列都需要填写

示例数据:

Staging: budget_line|date |fund|amount|description|PO_number 1 |20140623 |xyz |12.00 |donut |{null} 1 |{null} |xyz |3.00 |{null} |12345 1 |20140623 |abc |4.00 |tire |{null} 2 |20140623 |xyz |12.00 |donut |{null} 1 |20140623 |xyz |12.00 |bobs donut |{null} 我一直是这样做的:

插入主 选择预算行 日期 基金 数量 描述 ,邮政编码 从登台 不存在的地方 选择预算行 日期 基金 数量 描述 ,邮政编码 从主要 其中Staging.budget\u行=Main.budget\u行 或 Staging.budget\u行为空,Main.budget\u行为空 和 Staging.date=Main.date 或 Staging.date为空,Main.date为空 和 Staging.fund=Main.fund 或 Staging.fund为空,Main.fund为空 和 Staging.amount=Main.amount 或 Staging.amount为null,Main.amount为null 和 Staging.description=Main.description 或 Staging.description为null,Main.description为null 和 Staging.PO\u编号=Main.PO\u编号 或 Staging.PO_编号为空,Main.PO_编号为空


我得到了一些不来的,我不知道为什么。但我有大约28个字段。有更简单的方法吗?

空处理有问题

请尝试此操作-它将所有字段连接到一个键列中,并测试:

INSERT INTO Main
SELECT budget_line
,date
,fund
,amount
,description
,PO_number
FROM Staging
WHERE NOT EXISTS (
   SELECT 1
   FROM Main
   WHERE Staging.budget_line & Staging.date & Staging.fund & Staging.amount & Staging.description & Staging.PO_number =
   Main.budget_line & Main.date & Main.fund & Main.amount & Main.description & Main.PO_number)

我会在有机会的时候测试这个,但它应该会起作用。我想到了这一点,但认为空值会弄乱concat,所以我没有使用它。谢谢!
INSERT INTO Main
SELECT budget_line
,date
,fund
,amount
,description
,PO_number
FROM Staging
WHERE NOT EXISTS (
   SELECT 1
   FROM Main
   WHERE Staging.budget_line & Staging.date & Staging.fund & Staging.amount & Staging.description & Staging.PO_number =
   Main.budget_line & Main.date & Main.fund & Main.amount & Main.description & Main.PO_number)