我创建了一个使用左连接的查询。由于我不明白的原因,它将加入两个不同长度的字符串,就好像它们是相同的一样。一个例子是:
Left column = "351-561"
Right Column = "351-561-35C"
Result = Joined as equal.
我的解决方法是将字符串右键填充到相同的长度。我不明白为什么这两个字符串会被视为平等。
语法中是否有某种机制可以改变这种行为?
d
答案 0 :(得分:3)
您可能需要使用Visual Fox Pro
中的==
运算符
答案 1 :(得分:1)
在Visual FoxPro中,=运算符意味着相等。 ==运算符意味着“完全相等”。换句话说,==运算符比较每个表达式的大小和值。例如:
* Returns .T. because the first 3 characters on the left match the right. ? "123" = "12345" * Returns .F. because the expression sizes are not equal. ? "123" == "12345"
话虽这么说,我认为JOIN失败的唯一原因是因为您加入的列的大小不同。例如,此查询仅返回555-1234记录,因为CHAR列会自动用空格填充。
CREATE CURSOR "MyLeft" (LeftPK I, LeftCode C(20)) INSERT INTO "MyLeft" VALUES(1, "351-561") INSERT INTO "MyLeft" VALUES(2, "555-1234") CREATE CURSOR "MyRight" (RightPK I, RightCode C(20)) INSERT INTO "MyRight" VALUES(1, "351-561-35C") INSERT INTO "MyRight" VALUES(2, "555-1234") SELECT MyLeft.*, MyRight.* FROM "MyLeft" JOIN "MyRight" ON LeftCode = RightCode
此查询返回两个记录,因为列类型为VARCHAR。
CREATE CURSOR "MyLeft" (LeftPK I, LeftCode V(20)) INSERT INTO "MyLeft" VALUES(1, "351-561") INSERT INTO "MyLeft" VALUES(2, "555-1234") CREATE CURSOR "MyRight" (RightPK I, RightCode V(20)) INSERT INTO "MyRight" VALUES(1, "351-561-35C") INSERT INTO "MyRight" VALUES(2, "555-1234") SELECT MyLeft.*, MyRight.* FROM "MyLeft" JOIN "MyRight" ON LeftCode = RightCode