Warm tip: This article is reproduced from stackoverflow.com, please click
vb6 adodb recordset

ADO Recordset filter comparing two fields

发布于 2020-04-08 23:39:48

How can I filter a recordset by comparing two fields?

For a given ADO Recordset with n fields (Field1, Field2,...,Fieldn)

I used to filter a field against a value:

rs.Filter = "Field1 = 'something'"

But what I need to do is something like this:

rs.Filter = "Field1 = Field2"

Is that possible?

Questioner
Yoa
Viewed
17
Bob77 2020-02-07 06:09

The criteria string is made up of clauses in the form FieldName-Operator-Value

Value is the value with which you will compare the field values (for example, 'Smith', #8/24/95#, 12.345, or $50.00). Use single quotes with strings and pound signs (#) with dates. For numbers, you can use decimal points, dollar signs, and scientific notation. If Operator is LIKE, Value can use wildcards. Only the asterisk (*) and percent sign (%) wild cards are allowed, and they must be the last character in the string. Value cannot be null.

This suggests that comparing fields to each other is not supported. Value must be a literal.