我想基于两列已合并(通常不完美)到另一个表列中的两个表。我试图加入表格,因此正确的记录是相互关联的,所以我可以比较FDebit
和Debit
字段。基于已解析的列内容加入两个表
FMEMO
通常是通过取Num
,然后添加space
,然后添加Memo
文本生成的。正如你在下面看到的,我们的过程还不完美。因此,我想匹配Num
,然后space
,然后将备注字段的前10个字符匹配到FMEMO
字段。
我已经在示例数据下面包含代码。你能否提供一些关于如何做到这一点的建议?
发票表
MEMO民借记
用品。索托卡诺1135 2.25
吸水管(1-1/2 “)由食品3 74.04
软管/管件:编织管(1” 由食物3 98.72
QP10迈尔斯表面泵(60HZ)3 206.27
) 笼包括˚F罐,明矾零件盒和2桶明矾3 752.03
笼包括阀歧管,F1 & F2 3 3774.08
笼IBC在它1135 268.41
聚氯乙烯饰品安装LWTS的。 1175 4.26
用于安装LWTS的Pvc配件。 1175 27.26
费用表
FMEMO FDebit 用品。索托卡诺41.8 2.25
3吸水管(1-1/2 74.04
3软管/管件:编织管(1 98.72
3 QP10迈尔斯表面泵(60HZ)3970 206.27
3笼包括˚F罐,明矾份明矾的箱和2桶14474 752.03
3笼包括阀歧管,F1 & F2 72638 3774.08
3笼IBC在它5166 268.41
1175聚氯乙烯饰品安装LWTS的。82.03 4.26
1175聚氯乙烯饰品安装LWTS。524.67 27.26
代码复制:
CREATE TABLE #tempExpenses (
FMEMO varchar(Max), FDebit money)
CREATE TABLE #tempInvoices (
MEMO varchar(Max), Num integer, DEBIT money)
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('Supplies. Soto Cano 41.8', 2.25)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('3 Suction Hose (1-1/2', 74.04)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('3 Hose/Tubing:Braided Hose (1', 98.72)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('3 QP10 Meyers surface pump (60hz) 3970', 206.27)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('3 Cage including f tank, alum parts box and 2 buckets of alum 14474', 752.03)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('3 Cage including valve manifold, F1 & F2 72638', 3774.08)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('3 cage with IBC in it 5166', 268.41)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('1175 Pvc accesories for installation of LWTS. 82.03', 4.26)<br/>
INSERT INTO #tempExpenses (FMEMO, FDEBIT) VALUES ('1175 Pvc accesories for installation of LWTS. 524.67', 27.26)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Supplies. Soto Cano', 1135, 2.25)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Suction Hose (1-1/2") by the food', 3, 74.04)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Hose/Tubing:Braided Hose (1") by the food', 3, 98.72)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('QP10 Meyers surface pump (60hz)', 3, 206.27)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Cage including f tank, alum parts box and 2 buckets of alum', 3, 752.03)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Cage including valve manifold, F1 & F2', 3, 3774.08)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('cage with IBC in it', 1135, 268.41)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Pvc accesories for installation of LWTS.', 1175, 4.26)<br/>
INSERT INTO #tempInvoices (MEMO, Num, DEBIT) VALUES ('Pvc accesories for installation of LWTS.', 1175, 27.26)<br/>
SELECT *
FROM #tempExpenses
SELECT *
FROM #tempInvoices
我认为你的时间会更好地花在修复你的数据库设计上。希望谁决定这样设置它已经被解雇了。 –